Class ResolverCollection
ResolverCollection
is used for aggregating multiple resolvers when more than
one resolver is necessary. The collection will iterate over configured resolvers
and try to resolve a policy on each one. The first successfully resolved policy
will be returned.
Configured resolvers must throw Authorization\Policy\Exception\MissingPolicyException
if a policy cannot be resolved.
Example configuration:
$collection = new ResolverCollection([
new OrmResolver(),
new MapResolver([
Service::class => ServicePolicy::class
])
]);
$service = new AuthorizationService($collection);
Property Summary
-
$resolvers protected
arrayAuthorization\Policy\ResolverInterface>
Policy resolver instances.
Method Summary
-
__construct() public
Constructor. Takes an array of policy resolver instances.
-
add() public
Adds a resolver to the collection.
-
getPolicy() public
Resolves the policy object based on the authorization resource.
Method Detail
__construct() ¶ public
__construct(arrayAuthorization\Policy\ResolverInterface> $resolvers = [])
Constructor. Takes an array of policy resolver instances.
Parameters
-
arrayAuthorization\Policy\ResolverInterface>
$resolvers optional An array of policy resolver instances.
add() ¶ public
add(Authorization\Policy\ResolverInterface $resolver): $this
Adds a resolver to the collection.
Parameters
-
Authorization\Policy\ResolverInterface
$resolver Resolver instance.
Returns
$this
getPolicy() ¶ public
getPolicy(mixed $resource): mixed
Resolves the policy object based on the authorization resource.
The resolver MUST throw the \Authorization\Policy\Exception\MissingPolicyException
exception if a policy cannot be resolved for a given resource.
Parameters
-
mixed
$resource
Returns
mixed