Automattic\WooCommerce\Api\Infrastructure

ResolverHelpers::collect_authorization_instances │ private static │ WC 1.0

Collect attribute instances declared on $source whose class declares an authorization-shaped authorize() method.

Mirrors {@see \Automattic\WooCommerce\Api\Infrastructure\DesignTime\ApiBuilder::collect_authorization_usages()} for the runtime path: same direct-then-inherited precedence, same "any class with a bool-returning authorize() method qualifies" rule.

Method of the class: ResolverHelpers{}

No Hooks.

Returns

array<int, object>.

Usage

$result = ResolverHelpers::collect_authorization_instances( $source ): array;
$source(ReflectionClass) (required)
Class/trait/interface to read attributes from.

ResolverHelpers::collect_authorization_instances() code WC 11.1.2

private static function collect_authorization_instances( \ReflectionClass $source ): array {
	$instances = array();
	foreach ( $source->getAttributes() as $attr ) {
		$name = $attr->getName();
		if ( ! class_exists( $name ) || ! method_exists( $name, 'authorize' ) ) {
			continue;
		}
		$method = new \ReflectionMethod( $name, 'authorize' );
		if ( ! self::authorize_method_shape_is_valid( $method ) ) {
			continue;
		}
		$instances[] = $attr->newInstance();
	}
	return $instances;
}