Class OrmResolver
Policy resolver that applies conventions based policy classes for CakePHP ORM Tables, Entities and Queries.
Property Summary
-
$appNamespace protected
stringApplication namespace.
-
$container protected
?ContainerInterfaceThe DIC instance from the application
-
$overrides protected
array<string, string>Plugin name overrides.
Method Summary
-
__construct() public
Constructor
-
findPolicy() protected
Locate a policy class using conventions
-
getEntityPolicy() protected
Get a policy for an entity class.
-
getNamespace() protected
Returns plugin namespace override if exists.
-
getPolicy() public
Get a policy for an ORM Table, Entity, Query or class name string.
-
getRepositoryPolicy() protected
Get a policy for a table/repository class.
Method Detail
__construct() ¶ public
__construct(string $appNamespace = 'App', array<string, string> $overrides = [], Cake\Core\ContainerInterface|null $container = null)
Constructor
Parameters
-
string$appNamespace optional The application namespace
-
array<string, string>$overrides optional A list of plugin name overrides.
-
Cake\Core\ContainerInterface|null$container optional The DIC instance from the application
findPolicy() ¶ protected
findPolicy(string $class, string $name, string $namespace): mixed
Locate a policy class using conventions
Parameters
-
string$class The full class name.
-
string$name The name suffix of the resource.
-
string$namespace The namespace to find the policy in.
Returns
mixedThrows
Authorization\Policy\Exception\MissingPolicyExceptionWhen a policy for the resource has not been defined.
getEntityPolicy() ¶ protected
getEntityPolicy(string $class): mixed
Get a policy for an entity class.
Parameters
-
string$class The entity class name to get a policy for.
Returns
mixedgetNamespace() ¶ protected
getNamespace(string $namespace): string
Returns plugin namespace override if exists.
Parameters
-
string$namespace The namespace to find the policy in.
Returns
stringgetPolicy() ¶ public
getPolicy(mixed $resource): mixed
Get a policy for an ORM Table, Entity, Query or class name string.
Accepting an entity/table fully-qualified class name as the resource allows checks
like $user->can('add', Article::class) where no instance is on hand
(e.g. menu rendering before a newEmptyEntity()).
Parameters
-
mixed$resource The resource.
Returns
mixedThrows
Authorization\Policy\Exception\MissingPolicyExceptionWhen a policy for the resource has not been defined or cannot be resolved.
getRepositoryPolicy() ¶ protected
getRepositoryPolicy(string $class): mixed
Get a policy for a table/repository class.
Parameters
-
string$class The table/repository class name to get a policy for.
Returns
mixed