Automattic\WooCommerce\Api\Infrastructure
GraphQLControllerBase::resolve_request_principal
Resolve the request principal once per HTTP request.
Invoked eagerly at the top of {@see self::process_request()}, so a principal resolver throwing ApiException{} fails the request before any resolver runs (single coded error in the response, no data).
The principal is never null — anonymous requests are signalled by a principal whose authentication state is unauthenticated (for the default Principal{}, that's Principal::$user->ID === 0). Plugin resolvers can also signal "invalid credentials" by throwing ApiException.
The configured resolver's resolve_principal() may declare its \WP_REST_Request parameter or omit it; the autogenerated subclass overrides {@see self::principal_resolver_takes_request()} so this call uses the right arity without runtime reflection.
Method of the class: GraphQLControllerBase{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->resolve_request_principal( $request ): object;
- $request(WP_REST_Request) (required)
- The incoming REST request.
GraphQLControllerBase::resolve_request_principal() GraphQLControllerBase::resolve request principal code WC 10.9.4
private function resolve_request_principal( \WP_REST_Request $request ): object {
$fqcn = $this->get_principal_resolver_fqcn();
if ( null === $fqcn ) {
return new \Automattic\WooCommerce\Api\Infrastructure\Principal( wp_get_current_user() );
}
$resolver = $this->resolve_class( $fqcn );
return $this->principal_resolver_takes_request()
? $resolver->resolve_principal( $request )
: $resolver->resolve_principal();
}