CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C Authorization 3.x API

  • Project:
    • Authorization
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 3.x
      • 3.x
      • 2.x

Namespaces

  • Authorization
    • Command
    • Controller
    • Exception
    • Middleware
    • Policy
      • Exception

Class MapResolver

Policy resolver that allows to map policy classes, objects or factories to individual resource classes.

Namespace: Authorization\Policy

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.

Property Detail

$container ¶ protected

The DIC instance from the application

Type
Cake\Core\ContainerInterface|null

$map ¶ protected

Resource to policy class name map.

Type
array
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs