Class MapResolver
Policy resolver that allows to map policy classes, objects or factories to individual resource classes.
Property Summary
-
$container protected
Cake\Core\ContainerInterface|null
The DIC instance from the application
-
$map protected
array
Resource to policy class name map.
Method Summary
-
__construct() public
Constructor.
-
getPolicy() public
Resolves the policy object based on the authorization resource.
-
map() public
Maps a resource class to the policy class name.
Method Detail
__construct() ¶ public
__construct(array $map = [], Cake\Core\ContainerInterface|null $container = null)
Constructor.
Takes a resource class name as a key and a policy as a value, for example:
[
\App\Service\Resource1::class => \App\Policy\ResourcePolicy::class,
\App\Service\Resource2::class => $policyObject,
\App\Service\Resource3::class => function() {},
]
Parameters
-
array
$map optional Resource class name to policy map.
-
Cake\Core\ContainerInterface|null
$container optional The DIC instance from the application
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
Throws
InvalidArgumentException
When a resource is not an object.
Authorization\Policy\Exception\MissingPolicyException
When a policy for a resource has not been defined.
map() ¶ public
map(string $resourceClass, callable|object|string $policy): $this
Maps a resource class to the policy class name.
Parameters
-
string
$resourceClass A resource class name.
-
callable|object|string
$policy A policy class name, an object or a callable factory.
Returns
$this
Throws
InvalidArgumentException
When a resource class does not exist or policy is invalid.