Automattic\WooCommerce\Api\Infrastructure
Main::instantiate_graphql_controller
Instantiate a GraphQL controller subclass and wire up its dependencies.
Intended for sibling WooCommerce plugins that ship their own autogenerated GraphQLController subclass (emitted by build-api.php into their own autogenerated namespace). The returned controller is ready to have handle_request() attached to a REST route.
Returns null when the feature flag is off or PHP is < 8.1, so callers can invoke this unconditionally from inside their own rest_api_init handler.
Method of the class: Main{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = Main::instantiate_graphql_controller( $controller_class_name ): ?GraphQLControllerBase;
- $controller_class_name(string) (required)
- Fully-qualified name of a subclass of GraphQLControllerBase.
Main::instantiate_graphql_controller() Main::instantiate graphql controller code WC 10.9.1
public static function instantiate_graphql_controller( string $controller_class_name ): ?GraphQLControllerBase {
if ( ! self::is_enabled() ) {
return null;
}
self::assert_is_controller_subclass( $controller_class_name );
$controller = new $controller_class_name();
$controller->init( wc_get_container()->get( QueryCache::class ) );
return $controller;
}