Automattic\WooCommerce\Internal\PushNotifications\Notifications

Notification::from_array │ public static │ WC 10.7.0

Reconstructs a Notification subclass from a serialized array.

type and resource_id are required. Any further keys are passed to the subclass's hydrate() method, which decides what it recognises; see StockNotification::hydrate().

Метод класса: Notification{}

Хуков нет.

Возвращает

self.

Использование

$result = Notification::from_array( $data ): self;
$data(array<string, mixed>) (обязательный)
The notification data.

Список изменений

С версии 10.7.0 Введена.

Код Notification::from_array() WC 11.3.0

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 ) );
	}

	$instance = new $class( $resource_id );

	if ( method_exists( $instance, 'hydrate' ) ) {
		$instance->hydrate( $data );
	}

	return $instance;
}