Automattic\WooCommerce\Internal\Admin\Settings
PaymentsRestController::prepare_payment_providers_response_recursive
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() PaymentsRestController::prepare payment providers response recursive WC 10.4.3
private function prepare_payment_providers_response_recursive( $response_item, array $schema ) {
if ( is_null( $response_item ) ) {
return null;
}
if ( ! array_key_exists( 'properties', $schema ) ||
! is_array( $schema['properties'] ) ) {
// Filter out null values for loosely defined schema types.
if ( is_array( $response_item ) ) {
return ArrayUtil::filter_null_values_recursive( $response_item );
}
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.
return ArrayUtil::filter_null_values_recursive( $prepared_response );
}