Automattic\WooCommerce\Internal\Admin\Settings

PaymentsRestController::prepare_payment_providers_response_recursive()privateWC 1.0

Recursively prepare the response items for the GET payment providers request.

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

Хуков нет.

Возвращает

Разное. The prepared response item.

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

// private - только в коде основоного (родительского) класса
$result = $this->prepare_payment_providers_response_recursive( $response_item, $schema );
$response_item(разное) (обязательный)
The response item to prepare.
$schema(массив) (обязательный)
The schema to use for preparing the response.

Код PaymentsRestController::prepare_payment_providers_response_recursive() WC 9.6.1

private function prepare_payment_providers_response_recursive( $response_item, array $schema ) {
	if ( is_null( $response_item ) ||
		! array_key_exists( 'properties', $schema ) ||
		! is_array( $schema['properties'] ) ) {
		return $response_item;
	}

	$prepared_response = array();
	foreach ( $schema['properties'] as $key => $property_schema ) {
		if ( is_array( $response_item ) && array_key_exists( $key, $response_item ) ) {
			if ( is_array( $property_schema ) && array_key_exists( 'properties', $property_schema ) ) {
				$prepared_response[ $key ] = $this->prepare_payment_providers_response_recursive( $response_item[ $key ], $property_schema );
			} elseif ( is_array( $property_schema ) && array_key_exists( 'items', $property_schema ) ) {
				$prepared_response[ $key ] = array_map(
					fn( $item ) => $this->prepare_payment_providers_response_recursive( $item, $property_schema['items'] ),
					$response_item[ $key ]
				);
			} else {
				$prepared_response[ $key ] = $response_item[ $key ];
			}
		}
	}

	// Ensure the order is the same as in the schema.
	$prepared_response = array_merge( array_fill_keys( array_keys( $schema['properties'] ), null ), $prepared_response );

	// Remove any null values from the response.
	$prepared_response = array_filter( $prepared_response, fn( $value ) => ! is_null( $value ) );

	return $prepared_response;
}