Schema
4 weeks ago
ClassResolver.php
4 weeks ago
GraphQLControllerBase.php
4 weeks ago
Main.php
4 weeks ago
MetadataController.php
4 weeks ago
Principal.php
4 weeks ago
PrincipalResolver.php
4 weeks ago
QueryInfoExtractor.php
4 weeks ago
ResolverHelpers.php
4 weeks ago
PrincipalResolver.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Api\Infrastructure; |
| 6 | |
| 7 | /** |
| 8 | * Default principal resolver for the WooCommerce dual code+GraphQL API. |
| 9 | * |
| 10 | * Plugins that implement their own API and authenticate against something |
| 11 | * other than WordPress users (e.g. an app token) must ship their own resolver |
| 12 | * at `<plugin-api-namespace>\Infrastructure\PrincipalResolver` with a |
| 13 | * `resolve_principal( \WP_REST_Request ): T` (or zero-arg) method whose |
| 14 | * return type is the plugin's own principal class. ApiBuilder detects it |
| 15 | * during generation and routes the autogenerated controller through it. |
| 16 | * |
| 17 | * The \WP_REST_Request parameter is optional; the default resolver doesn't |
| 18 | * inspect headers (WordPress's auth pipeline has already populated the global |
| 19 | * current user by the time this fires). |
| 20 | */ |
| 21 | final class PrincipalResolver { |
| 22 | /** |
| 23 | * Resolve the request principal. |
| 24 | * |
| 25 | * Anonymous requests are signalled by a Principal whose underlying |
| 26 | * `WP_User` has `ID === 0` (see {@see Principal::is_authenticated()}). |
| 27 | */ |
| 28 | public function resolve_principal(): Principal { |
| 29 | return new Principal( wp_get_current_user() ); |
| 30 | } |
| 31 | } |
| 32 |