Automattic\WooCommerce\Internal\PushNotifications\Notifications

Notification::from_arraypublic staticWC 10.7.0

Reconstructs a Notification subclass from a serialized array.

Method of the class: Notification{}

No Hooks.

Returns

self.

Usage

$result = Notification::from_array( $data ): self;
$data(array) (required)
.

Changelog

Since 10.7.0 Introduced.

Notification::from_array() code WC 10.8.1

public static function from_array( array $data ): self {
	$type        = $data['type'] ?? '';
	$resource_id = (int) ( $data['resource_id'] ?? 0 );

	$class = self::NOTIFICATION_CLASSES[ $type ] ?? null;

	if ( ! $class ) {
		// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
		throw new InvalidArgumentException( sprintf( 'Unknown notification type: %s', $type ) );
	}

	return new $class( $resource_id );
}