�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`�
Warning: session_start(): Session cannot be started after headers have already been sent in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 124

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 130

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 131

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 133

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 134

Warning: Cannot modify header information - headers already sent by (output started at /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php:1) in /home/mciraet/www/wp-includes/php-ai-client/src/Providers/Enums/Documentsoliders.php on line 135
0x0x
PHP 8.2.31
Preview: Main.php Size: 15.65 KB
/home/mciraet/www/wp-content/plugins/woocommerce/src/Api/Infrastructure/Main.php
<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Api\Infrastructure;

use Automattic\WooCommerce\Internal\Api\Autogenerated;
use Automattic\WooCommerce\Internal\Api\GraphQLEndpointRegistrar;
use Automattic\WooCommerce\Internal\Api\OpcacheFileExpiry;
use Automattic\WooCommerce\Internal\Api\QueryCache;
use Automattic\WooCommerce\Internal\Api\Settings;
use Automattic\WooCommerce\Utilities\FeaturesUtil;

/**
 * Entry point for the WooCommerce GraphQL API.
 *
 * This class is intentionally free of PHP 8.0+ syntax so that it can be
 * loaded and called on PHP 7.4 without parse errors. The PHP-8.1-only
 * classes (GraphQLControllerBase, QueryCache, etc.) are resolved lazily
 * from the DI container only after is_enabled() confirms PHP 8.1+ is
 * available.
 */
class Main {
	/**
	 * Feature flag slug registered in FeaturesController.
	 */
	private const FEATURE_SLUG = 'dual_code_graphql_api';

	/**
	 * Option name for the "Enable GET endpoint" setting.
	 *
	 * When disabled, the GraphQL route only accepts POST requests.
	 */
	public const OPTION_GET_ENDPOINT_ENABLED = 'woocommerce_graphql_get_endpoint_enabled';

	/**
	 * Option name for the "Enable APQ caching" setting.
	 *
	 * When disabled, the persistedQuery extension is ignored and requests are
	 * treated as standard queries.
	 */
	public const OPTION_APQ_ENABLED = 'woocommerce_graphql_apq_enabled';

	/**
	 * Option name for the "Endpoint URL" setting.
	 *
	 * Path (relative to /wp-json/) at which the GraphQL route is registered.
	 */
	public const OPTION_ENDPOINT_URL = 'woocommerce_graphql_endpoint_url';

	/**
	 * Option name for the "Maximum query depth" setting.
	 *
	 * Caps how deep the selection tree of a GraphQL query may nest.
	 */
	public const OPTION_MAX_QUERY_DEPTH = 'woocommerce_graphql_max_query_depth';

	/**
	 * Option name for the "Maximum query complexity" setting.
	 *
	 * Caps the computed complexity score of a GraphQL query — connection
	 * fields multiply their children's cost by the requested page size.
	 */
	public const OPTION_MAX_QUERY_COMPLEXITY = 'woocommerce_graphql_max_query_complexity';

	/**
	 * Option name for the "OPcache-based caching" setting.
	 *
	 * When enabled, parsed query ASTs are written to disk as PHP files so
	 * that OPcache serves them from shared memory on subsequent requests.
	 */
	public const OPTION_OPCACHE_ENABLED = 'woocommerce_graphql_opcache_enabled';

	/**
	 * Option name for the "ObjectCache-based caching" setting.
	 */
	public const OPTION_OBJECT_CACHE_ENABLED = 'woocommerce_graphql_object_cache_enabled';

	/**
	 * Option name for the "Parsed query cache TTL" setting.
	 *
	 * Time-to-live (in seconds) applied to parsed-query AST entries written
	 * to the WP object cache by both the standard-query and APQ paths.
	 */
	public const OPTION_QUERY_CACHE_TTL = 'woocommerce_graphql_query_cache_ttl';

	/**
	 * Check whether the Dual Code & GraphQL API feature is active.
	 *
	 * Requires PHP 8.1+ and the dual_code_graphql_api feature flag to be
	 * enabled.
	 *
	 * @return bool
	 */
	public static function is_enabled(): bool {
		return PHP_VERSION_ID >= 80100 && FeaturesUtil::feature_is_enabled( self::FEATURE_SLUG );
	}

	/**
	 * Whether the GraphQL endpoint accepts GET requests.
	 *
	 * Defaults to false. Reads from the option written by the GraphQL
	 * settings section so the REST route registration can decide which
	 * HTTP methods to accept.
	 */
	public static function is_get_endpoint_enabled(): bool {
		return wc_string_to_bool( get_option( self::OPTION_GET_ENDPOINT_ENABLED, 'yes' ) );
	}

	/**
	 * Whether the Apollo Automatic Persisted Queries (APQ) protocol is enabled.
	 *
	 * Defaults to true. When disabled, the `persistedQuery` request extension
	 * is ignored and requests are processed as standard (non-persisted) queries.
	 */
	public static function is_apq_enabled(): bool {
		return wc_string_to_bool( get_option( self::OPTION_APQ_ENABLED, 'yes' ) );
	}

	/**
	 * Whether the OPcache-backed query cache is enabled.
	 *
	 * Defaults to true. Activation also depends on OPcache being loaded and
	 * the cache directory being writable; see {@see QueryCache} for the
	 * runtime capability check.
	 */
	public static function is_opcache_enabled(): bool {
		return wc_string_to_bool( get_option( self::OPTION_OPCACHE_ENABLED, 'yes' ) );
	}

	/**
	 * Whether the ObjectCache-backed query cache is enabled.
	 *
	 * Defaults to true.
	 */
	public static function is_object_cache_enabled(): bool {
		return wc_string_to_bool( get_option( self::OPTION_OBJECT_CACHE_ENABLED, 'yes' ) );
	}

	/**
	 * Apply the GraphQL-scoped site settings to a caller-declared list of HTTP
	 * methods.
	 *
	 * Centralises the "what verbs does the admin actually allow on a GraphQL
	 * endpoint" rule so both WooCommerce core's own endpoint and every sibling
	 * plugin endpoint applied through {@see self::register_graphql_endpoint()}
	 * honour the same settings.
	 *
	 * Currently the only rule is: if the GET endpoint has been disabled in the
	 * GraphQL settings section, strip GET from the list.
	 *
	 * @param string[] $methods HTTP methods the caller declared.
	 * @return string[] Possibly narrowed list — may be empty, in which case the
	 *                 caller should skip the route registration entirely.
	 */
	public static function filter_methods_against_settings( array $methods ): array {
		if ( ! self::is_get_endpoint_enabled() ) {
			$methods = array_values( array_diff( $methods, array( 'GET' ) ) );
		}
		return $methods;
	}

	/**
	 * Register the GraphQL endpoint when the feature is active.
	 *
	 * When the feature is off this is a no-op. Classes in the public
	 * Automattic\WooCommerce\Api\ namespace remain autoloadable — extensions
	 * that want to know whether the feature is active should check
	 * FeaturesUtil::feature_is_enabled( 'dual_code_graphql_api' ) rather
	 * than class_exists() on the Api namespace.
	 *
	 * The feature-enabled check is deferred to the `rest_api_init` callback
	 * to avoid triggering translation loading (via FeaturesController) before
	 * the `init` action has fired, which would cause a
	 * `_load_textdomain_just_in_time` notice on WordPress 6.7+.
	 */
	public static function register(): void {
		add_action( 'rest_api_init', array( self::class, 'handle_rest_api_init_for_core' ) );

		$settings = wc_get_container()->get( Settings::class );
		$settings->register();

		add_action( OpcacheFileExpiry::ACTION_HOOK, array( OpcacheFileExpiry::class, 'handle_cleanup_action' ) );
	}

	/**
	 * Hook callback: register WooCommerce core's GraphQL endpoint.
	 *
	 * @internal
	 */
	public static function handle_rest_api_init_for_core(): void {
		if ( ! self::is_enabled() ) {
			return;
		}

		wc_get_container()->get( Autogenerated\GraphQLController::class )->register();
	}

	/**
	 * 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.
	 *
	 * @param string $controller_class_name Fully-qualified name of a subclass of GraphQLControllerBase.
	 *
	 * @throws \InvalidArgumentException If $controller_class_name does not extend GraphQLControllerBase.
	 */
	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;
	}

	/**
	 * Register a GraphQL REST endpoint backed by a plugin-provided controller subclass.
	 *
	 * May be called at any time up to and including the `rest_api_init` hook:
	 * if called earlier, registration is deferred to that hook; if called from
	 * inside another plugin's `rest_api_init` handler, registration happens
	 * immediately. Calls made after `rest_api_init` has already completed
	 * register a REST route that WP_REST_Server won't honour on the current
	 * request — callers should avoid deferring registration past bootstrap.
	 *
	 * When the feature flag is off or PHP is < 8.1 this is a silent no-op.
	 *
	 * The first argument accepts either of two forms:
	 *
	 *  - A plugin root directory (recommended): pass `__DIR__` from the plugin's
	 *    bootstrap file. The controller class is resolved by convention from
	 *    `{dir}/src/Internal/Api/Autogenerated/GraphQLController.php` — ApiBuilder
	 *    always emits the generated subclass at that path.
	 *  - A controller class FQCN: use this when the plugin keeps its generated
	 *    code somewhere other than the conventional location, or registers
	 *    multiple endpoints backed by different controller classes.
	 *
	 * Plugins calling this method should guard the call with method_exists():
	 *
	 *     if ( method_exists( \Automattic\WooCommerce\Api\Infrastructure\Main::class, 'register_graphql_endpoint' ) ) {
	 *         \Automattic\WooCommerce\Api\Infrastructure\Main::register_graphql_endpoint(
	 *             __DIR__,
	 *             'my-plugin',
	 *             '/graphql'
	 *         );
	 *     }
	 *
	 * @param string   $plugin_dir_or_controller_class Plugin root directory, OR a fully-qualified GraphQLController subclass name. See above.
	 * @param string   $route_namespace                REST route namespace, as passed to register_rest_route().
	 * @param string   $route                          REST route path, as passed to register_rest_route().
	 * @param string[] $methods                        HTTP methods accepted on the endpoint. Defaults to GET + POST.
	 *
	 * @throws \InvalidArgumentException If no controller can be resolved from a directory argument, or if the resolved class does not extend GraphQLControllerBase.
	 */
	public static function register_graphql_endpoint(
		string $plugin_dir_or_controller_class,
		string $route_namespace,
		string $route,
		array $methods = array( 'GET', 'POST' )
	): void {
		if ( ! self::is_enabled() ) {
			return;
		}

		$controller_class_name = self::resolve_controller_class( $plugin_dir_or_controller_class );

		// Validate up front so a typo surfaces here at bootstrap rather than
		// deep inside the deferred rest_api_init callback.
		self::assert_is_controller_subclass( $controller_class_name );

		$registrar = new GraphQLEndpointRegistrar( $controller_class_name, $route_namespace, $route, $methods );

		if ( did_action( 'rest_api_init' ) ) {
			$registrar->handle_rest_api_init();
		} else {
			add_action( 'rest_api_init', array( $registrar, 'handle_rest_api_init' ) );
		}
	}

	/**
	 * 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.
	 *
	 * @param string $arg Either a plugin root directory or a controller class FQCN.
	 *
	 * @throws \InvalidArgumentException If the argument is a directory but the
	 *                                   generated controller file is missing or
	 *                                   doesn't declare a PHP namespace.
	 */
	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';
	}

	/**
	 * Extract an unbracketed `namespace …;` declaration from a PHP source fragment.
	 *
	 * Uses PHP's tokenizer rather than a regex so the parse isn't fooled by
	 * declarations inside heredocs, comments, or bracketed-namespace syntax,
	 * and continues to work if the generator's output format changes
	 * (e.g. attributes before the declaration, single-line `<?php namespace`).
	 *
	 * @param string $source PHP source code.
	 * @return ?string The namespace FQN without leading or trailing separator, or null if none found.
	 */
	private static function extract_namespace_from_php_source( string $source ): ?string {
		$tokens = token_get_all( $source );
		$count  = count( $tokens );
		for ( $i = 0; $i < $count; $i++ ) {
			if ( ! is_array( $tokens[ $i ] ) || T_NAMESPACE !== $tokens[ $i ][0] ) {
				continue;
			}
			$namespace = '';
			for ( $j = $i + 1; $j < $count; $j++ ) {
				$token = $tokens[ $j ];
				if ( is_array( $token ) ) {
					// T_NAME_QUALIFIED and T_NAME_FULLY_QUALIFIED exist on PHP 8+ and already
					// contain the full namespace path; T_STRING / T_NS_SEPARATOR are the
					// equivalent pieces on older versions.
					if ( in_array( $token[0], array( T_STRING, T_NS_SEPARATOR ), true )
						|| ( defined( 'T_NAME_QUALIFIED' ) && T_NAME_QUALIFIED === $token[0] )
						|| ( defined( 'T_NAME_FULLY_QUALIFIED' ) && T_NAME_FULLY_QUALIFIED === $token[0] ) ) {
						$namespace .= $token[1];
						continue;
					}
					if ( T_WHITESPACE === $token[0] ) {
						continue;
					}
				}
				// Single-character tokens `;` (unbracketed namespace) and `{` (bracketed) end the declaration.
				break;
			}
			$namespace = trim( $namespace, '\\' );
			if ( '' !== $namespace ) {
				return $namespace;
			}
		}
		return null;
	}

	/**
	 * Assert that a class name resolves to a concrete GraphQLControllerBase subclass.
	 *
	 * @param string $controller_class_name Fully-qualified name of the class to validate.
	 *
	 * @throws \InvalidArgumentException If the class cannot be autoloaded, or does not extend GraphQLControllerBase.
	 */
	private static function assert_is_controller_subclass( string $controller_class_name ): void {
		// Differentiate "class does not exist" (typo / stale autoloader) from
		// "class exists but is not a subclass" — is_subclass_of() collapses
		// both into false, which is confusing when debugging a bootstrap typo.
		if ( ! class_exists( $controller_class_name ) ) {
			throw new \InvalidArgumentException(
				sprintf(
					'GraphQL controller class "%s" does not exist or is not autoloadable. Check the spelling, or run `composer dump-autoload` if it was added since the last autoloader regeneration.',
					esc_html( $controller_class_name )
				)
			);
		}
		if ( ! is_subclass_of( $controller_class_name, GraphQLControllerBase::class ) ) {
			throw new \InvalidArgumentException(
				sprintf(
					'Class "%s" must extend %s.',
					esc_html( $controller_class_name ),
					esc_html( GraphQLControllerBase::class )
				)
			);
		}
	}
}

Directory Contents

Dirs: 1 × Files: 8
Name Size Perms Modified Actions
Schema DIR
- drwxr-xr-x 2026-08-11 10:05:47
Edit Download
945 B lrw-r--r-- 2026-08-11 10:05:47
Edit Download
41.99 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
15.65 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
15.63 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
2.43 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
1.12 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
7.35 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
19.25 KB lrw-r--r-- 2026-08-11 10:05:47
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI