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
ClassResolver.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Api\Infrastructure; |
| 6 | |
| 7 | /** |
| 8 | * Class resolver for code-API command classes and other infrastructure classes. |
| 9 | * |
| 10 | * Plugins that implement their own API and want their command and infrastructure |
| 11 | * classes instantiated through a container of their own can ship their own |
| 12 | * ClassResolver class at `<plugin-api-namespace>\Infrastructure\ClassResolver` |
| 13 | * with the same public signature: ApiBuilder detects it during generation |
| 14 | * and routes the generated resolvers through it. When no such class is present, |
| 15 | * resolvers fall back to `new $class_name()`. |
| 16 | */ |
| 17 | final class ClassResolver { |
| 18 | /** |
| 19 | * Resolve a class to an instance. |
| 20 | * |
| 21 | * @param string $class_name Fully qualified name of the class to resolve. |
| 22 | * @return object An instance of $class_name. |
| 23 | */ |
| 24 | public static function resolve_class( string $class_name ): object { |
| 25 | return wc_get_container()->get( $class_name ); |
| 26 | } |
| 27 | } |
| 28 |