WooCommerce Code Reference

Hydration
in package

Service class that handles hydration of API data for blocks.

Table of Contents

$asset_data_registry  : AssetDataRegistry
Instance of the asset data registry.
$cached_store_notices  : array<string|int, mixed>
Cached notices to restore after hydrating the API.
__construct()  : mixed
Constructor.
disable_nonce_check_callback()  : mixed
Callback to disable the nonce check. While we could use `__return_true`, we use a custom named callback so that we can remove it later without affecting other filters.
get_rest_api_response_data()  : array<string|int, mixed>
Hydrates the asset data registry with data from the API. Disables notices and nonces so requests contain valid data that is not polluted by the current session.
cache_store_notices()  : mixed
Cache notices before hydrating the API if the customer has a session.
disable_nonce_check()  : mixed
Disable the nonce check temporarily.
restore_cached_store_notices()  : mixed
Restore notices into current session from cache.
restore_nonce_check()  : mixed
Restore the nonce check.
get_response_from_controller()  : false|mixed|null
Helper method to generate GET response from a controller. Also fires the `rest_request_after_callbacks` for backward compatibility.
match_route_to_handler()  : string|null
Inspired from WP core's `match_request_to_handler`, this matches a given path from available route regexes.

Properties

Methods

disable_nonce_check_callback()

Callback to disable the nonce check. While we could use `__return_true`, we use a custom named callback so that we can remove it later without affecting other filters.

public disable_nonce_check_callback() : mixed
Return values
mixed

get_rest_api_response_data()

Hydrates the asset data registry with data from the API. Disables notices and nonces so requests contain valid data that is not polluted by the current session.

public get_rest_api_response_data([array<string|int, mixed> $path = '' ]) : array<string|int, mixed>
Parameters
$path : array<string|int, mixed> = ''

API paths to hydrate e.g. '/wc/store/v1/cart'.

Return values
array<string|int, mixed>Response data.

cache_store_notices()

Cache notices before hydrating the API if the customer has a session.

protected cache_store_notices() : mixed
Return values
mixed

restore_cached_store_notices()

Restore notices into current session from cache.

protected restore_cached_store_notices() : mixed
Return values
mixed

get_response_from_controller()

Helper method to generate GET response from a controller. Also fires the `rest_request_after_callbacks` for backward compatibility.

private get_response_from_controller(string $controller_class, string $path) : false|mixed|null
Parameters
$controller_class : string

Controller class FQN that will respond to the request.

$path : string

Request path regex.

Return values
false|mixed|nullResponse

match_route_to_handler()

Inspired from WP core's `match_request_to_handler`, this matches a given path from available route regexes.

private match_route_to_handler(string $path, array<string|int, mixed> $available_routes) : string|null

However, unlike WP core, this does not check against query params, request method etc.

Parameters
$path : string

The path to match.

$available_routes : array<string|int, mixed>

Available routes in { $regex1 => $contoller_class1, ... } format.

Return values
string|null