extends abstract class Phalcon\Acl\Adapter
implements Phalcon\Events\EventsAwareInterface, Phalcon\Acl\AdapterInterface
Manages ACL lists in memory
$acl = new \Phalcon\Acl\Adapter\Memory(); $acl->setDefaultAction( \Phalcon\Acl::DENY ); // Register roles $roles = [ "users" => new \Phalcon\Acl\Role("Users"), "guests" => new \Phalcon\Acl\Role("Guests"), ]; foreach ($roles as $role) { $acl->addRole($role); } // Private area resources $privateResources = [ "companies" => ["index", "search", "new", "edit", "save", "create", "delete"], "products" => ["index", "search", "new", "edit", "save", "create", "delete"], "invoices" => ["index", "profile"], ]; foreach ($privateResources as $resourceName => $actions) { $acl->addResource( new \Phalcon\Acl\Resource($resourceName), $actions ); } // Public area resources $publicResources = [ "index" => ["index"], "about" => ["index"], "session" => ["index", "register", "start", "end"], "contact" => ["index", "send"], ]; foreach ($publicResources as $resourceName => $actions) { $acl->addResource( new \Phalcon\Acl\Resource($resourceName), $actions ); } // Grant access to public areas to both users and guests foreach ($roles as $role){ foreach ($publicResources as $resource => $actions) { $acl->allow($role->getName(), $resource, "*"); } } // Grant access to private area to role Users foreach ($privateResources as $resource => $actions) { foreach ($actions as $action) { $acl->allow("Users", $resource, $action); } }
Phalcon\Acl\Adapter\Memory constructor
Adds a role to the ACL list. Second parameter allows inheriting access data from other existing role Example:
$acl->addRole( new Phalcon\Acl\Role("administrator"), "consultant" ); $acl->addRole("administrator", "consultant");
Do a role inherit from another existing role
Check whether role exist in the roles list
Check whether resource exist in the resources list
Adds a resource to the ACL list Access names can be a particular action, by example search, update, delete, etc or a list of them Example:
// Add a resource to the the list allowing access to an action $acl->addResource( new Phalcon\Acl\Resource("customers"), "search" ); $acl->addResource("customers", "search"); // Add a resource with an access list $acl->addResource( new Phalcon\Acl\Resource("customers"), [ "create", "search", ] ); $acl->addResource( "customers", [ "create", "search", ] );
Adds access to resources
Removes an access from a resource
Checks if a role has access to a resource
Allow access to a role on a resource You can use ‘*’ as wildcard Example:
//Allow access to guests to search on customers $acl->allow("guests", "customers", "search"); //Allow access to guests to search or create on customers $acl->allow("guests", "customers", ["search", "create"]); //Allow access to any role to browse on products $acl->allow("*", "products", "browse"); //Allow access to any role to browse on any resource $acl->allow("*", "*", "browse");
Deny access to a role on a resource You can use ‘*’ as wildcard Example:
//Deny access to guests to search on customers $acl->deny("guests", "customers", "search"); //Deny access to guests to search or create on customers $acl->deny("guests", "customers", ["search", "create"]); //Deny access to any role to browse on products $acl->deny("*", "products", "browse"); //Deny access to any role to browse on any resource $acl->deny("*", "*", "browse");
Check whether a role is allowed to access an action from a resource
//Does andres have access to the customers resource to create? $acl->isAllowed("andres", "Products", "create"); //Do guests have access to any resource to edit? $acl->isAllowed("guests", "*", "edit");
Sets the default access level (Phalcon\Acl::ALLOW or Phalcon\Acl::DENY) for no arguments provided in isAllowed action if there exists func for accessKey
Returns the default ACL access level for no arguments provided in isAllowed action if there exists func for accessKey
Return an array with every role registered in the list
Return an array with every resource registered in the list
Role which the list is checking if it’s allowed to certain resource/access
Resource which the list is checking if some role can access it
Active access which the list is checking if some role can access it
Sets the events manager
Returns the internal event manager
Sets the default access level (Phalcon\Acl::ALLOW or Phalcon\Acl::DENY)
Returns the default ACL access level
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Acl_Adapter_Memory.html