Automattic\WooCommerce\Internal\PushNotifications\Notifications

StockNotification::hydratepublicWC 10.9.0

Restores extra state from a serialized notification array.

Called by Notification::from_array() after construction to restore the event type that the default constructor cannot receive.

Throws when event_type is present but unrecognized so the safety-net caller (which wraps reconstruction in a try/catch) drops the corrupt job rather than silently dispatching the wrong notification subtype. A missing event_type is allowed — the default set by the constructor survives, which preserves backward compatibility with any in-flight scheduled actions that pre-date this field.

Method of the class: StockNotification{}

No Hooks.

Returns

null. Nothing (null).

Usage

$StockNotification = new StockNotification();
$StockNotification->hydrate( $data ): void;
$data(array) (required)
The serialized notification data.

Changelog

Since 10.9.0 Introduced.

StockNotification::hydrate() code WC 10.9.1

public function hydrate( array $data ): void {
	if ( array_key_exists( 'event_type', $data ) ) {
		$event_type = $data['event_type'];

		if ( ! in_array( $event_type, self::VALID_EVENT_TYPES, true ) ) {
			// phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
			throw new InvalidArgumentException( sprintf( 'Invalid stock notification event type during hydrate: %s', is_scalar( $event_type ) ? (string) $event_type : gettype( $event_type ) ) );
		}

		$this->event_type = $event_type;
	}

	if ( array_key_exists( 'stock_quantity_at_trigger', $data ) ) {
		$stock                           = $data['stock_quantity_at_trigger'];
		$this->stock_quantity_at_trigger = is_int( $stock ) ? $stock : null;
	}
}