Automattic\WooCommerce\Blocks\Assets

AssetDataRegistry::hydrate_data_from_api_request()publicWC 1.0

Hydrate some data from the API.

Method of the class: AssetDataRegistry{}

No Hooks.

Return

null. Nothing (null).

Usage

$AssetDataRegistry = new AssetDataRegistry();
$AssetDataRegistry->hydrate_data_from_api_request( $key, $path, $check_key_exists );
$key(string) (required)
The key used to reference the data being registered.
$path(string) (required)
REST API path to preload.
$check_key_exists(true|false)
If set to true, duplicate data will be ignored if the key exists. If false, duplicate data will cause an exception.
Default: false

AssetDataRegistry::hydrate_data_from_api_request() code WC 9.2.3

public function hydrate_data_from_api_request( $key, $path, $check_key_exists = false ) {
	$this->add(
		$key,
		function () use ( $path ) {
			if ( isset( $this->preloaded_api_requests[ $path ], $this->preloaded_api_requests[ $path ]['body'] ) ) {
				return $this->preloaded_api_requests[ $path ]['body'];
			}
			$response = Package::container()->get( Hydration::class )->get_rest_api_response_data( $path );
			return $response['body'] ?? '';
		},
		$check_key_exists
	);
}