Automattic\WooCommerce\Internal

RestApiControllerBase::run()protectedWC 1.0

Handle a request for one of the provided REST API endpoints.

If an exception is thrown, the exception message will be returned as part of the response if the user has the 'manage_woocommerce' capability.

Note that the method specified in $method_name must have a 'protected' visibility and accept one argument of type 'WP_REST_Request'.

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

Хуков нет.

Возвращает

WP_Error|WP_HTTP_Response|WP_REST_Response. The response to send back to the client.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->run( $request, $method_name );
$request(WP_REST_Request) (обязательный)
The incoming HTTP REST request.
$method_name(строка) (обязательный)
The name of the class method to execute. It must be protected and accept one argument of type 'WP_REST_Request'.

Код RestApiControllerBase::run() WC 9.7.1

protected function run( WP_REST_Request $request, string $method_name ) {
	try {
		return rest_ensure_response( $this->$method_name( $request ) );
	} catch ( InvalidArgumentException $ex ) {
		$message = $ex->getMessage();
		return new WP_Error( 'woocommerce_rest_invalid_argument', $message ? $message : __( 'Internal server error', 'woocommerce' ), array( 'status' => 400 ) );
	} catch ( Exception $ex ) {
		wc_get_logger()->error( StringUtil::class_name_without_namespace( static::class ) . ": when executing method $method_name: {$ex->getMessage()}" );
		return $this->internal_wp_error( $ex );
	}
}