Automattic\WooCommerce\Api\Infrastructure
Main::resolve_controller_class
Resolve the first argument of {@see self::register_graphql_endpoint()} to a controller class name. If the argument is an existing directory, treat it as the plugin root and read the namespace from the generated controller file at the conventional path. Otherwise return the argument unchanged so it's used as a class FQCN.
Метод класса: Main{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = Main::resolve_controller_class( $arg ): string;
- $arg(строка) (обязательный)
- Either a plugin root directory or a controller class FQCN.
Код Main::resolve_controller_class() Main::resolve controller class WC 11.0.1
private static function resolve_controller_class( string $arg ): string {
if ( ! is_dir( $arg ) ) {
return $arg;
}
$controller_file = rtrim( $arg, '/\\' ) . '/src/Internal/Api/Autogenerated/GraphQLController.php';
if ( ! is_file( $controller_file ) ) {
throw new \InvalidArgumentException(
sprintf(
'Expected a generated GraphQL controller at %s, but the file does not exist. Run the plugin\'s API build script first, or pass an explicit controller class name.',
esc_html( $controller_file )
)
);
}
// The generated controller always declares its namespace near the top
// of the file; reading the first few KB is more than enough. Reading a
// local file — not a URL — so wp_remote_get() does not apply here.
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$head = file_get_contents( $controller_file, false, null, 0, 4096 );
if ( false === $head ) {
throw new \InvalidArgumentException(
sprintf( 'Could not read the controller file at %s.', esc_html( $controller_file ) )
);
}
$namespace = self::extract_namespace_from_php_source( $head );
if ( null === $namespace ) {
throw new \InvalidArgumentException(
sprintf( 'Could not determine the PHP namespace of the controller at %s.', esc_html( $controller_file ) )
);
}
return $namespace . '\\GraphQLController';
}