Automattic\WooCommerce\Api\Infrastructure

ResolverHelpers::authorize_method_shape_is_validprivate staticWC 1.0

Whether a method's shape matches the authorization-attribute contract: public, non-static, returns bool, and parameters drawn from the accepted set — at most one principal (any non-_-prefixed name, non-nullable typed) plus any subset of $_metadata (array), $_args (array), and $_parent (any type).

Mirrors the build-time ApiBuilder::validate_attribute_authorize_shape() check so the runtime helper recognises the same set of attributes ApiBuilder would have emitted into a resolver.

Method of the class: ResolverHelpers{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ResolverHelpers::authorize_method_shape_is_valid( $method ): bool;
$method(ReflectionMethod) (required)
The method to inspect.

ResolverHelpers::authorize_method_shape_is_valid() code WC 10.9.1

private static function authorize_method_shape_is_valid( \ReflectionMethod $method ): bool {
	if ( $method->isStatic() || ! $method->isPublic() ) {
		return false;
	}
	$return_type = $method->getReturnType();
	if ( ! $return_type instanceof \ReflectionNamedType || 'bool' !== $return_type->getName() ) {
		return false;
	}

	$principal_seen = false;
	foreach ( $method->getParameters() as $param ) {
		$name = $param->getName();
		if ( '_metadata' === $name || '_args' === $name ) {
			$type = $param->getType();
			if ( ! $type instanceof \ReflectionNamedType || 'array' !== $type->getName() ) {
				return false;
			}
			continue;
		}
		if ( '_parent' === $name ) {
			continue;
		}
		if ( '' !== $name && '_' === $name[0] ) {
			// Unknown infra parameter — reject.
			return false;
		}
		if ( $principal_seen ) {
			return false;
		}
		$type = $param->getType();
		if ( ! $type instanceof \ReflectionNamedType || $type->allowsNull() ) {
			return false;
		}
		$principal_seen = true;
	}
	return true;
}