- Phalcon\Acl\Adapter\AbstractAdapter
- Phalcon\Acl\Adapter\AdapterInterface
- Phalcon\Acl\Adapter\Memory
- Phalcon\Acl\Component
- Phalcon\Acl\ComponentAware
- Phalcon\Acl\ComponentInterface
- Phalcon\Acl\Enum
- Phalcon\Acl\Exception
- Phalcon\Acl\Role
- Phalcon\Acl\RoleAware
- Phalcon\Acl\RoleInterface
Abstract Class Phalcon\Acl\Adapter\AbstractAdapter
| Namespace | Phalcon\Acl\Adapter | | Uses | Phalcon\Acl\Enum, Phalcon\Events\ManagerInterface, Phalcon\Events\EventsAwareInterface | | Implements | AdapterInterface, EventsAwareInterface |
Adapter for Phalcon\Acl adapters
Properties¶
/**
* Active access which the list is checking if some role can access it
*
* @var string|null
*/
protected activeAccess;
/**
* Access Granted
*
* @var bool
*/
protected accessGranted = false;
/**
* Role which the list is checking if it's allowed to certain
* component/access
*
* @var string|null
*/
protected activeRole;
/**
* Component which the list is checking if some role can access it
*
* @var string|null
*/
protected activeComponent;
/**
* Default access
*
* @var int
*/
protected defaultAccess;
/**
* Events manager
*
* @var ManagerInterface|null
*/
protected eventsManager;
Methods¶
Returns the default ACL access level Returns the internal event manager Sets the default access level (Phalcon\Acl::ALLOW or Phalcon\Acl::DENY) Sets the events managerInterface Phalcon\Acl\Adapter\AdapterInterface
| Namespace | Phalcon\Acl\Adapter | | Uses | Phalcon\Acl\ComponentInterface, Phalcon\Acl\RoleInterface |
Interface for Phalcon\Acl adapters
Methods¶
Adds a component to the ACL listAccess names can be a particular action, by example search, update, delete, etc or a list of them
Adds access to components Do a role inherit from another existing role Adds a role to the ACL list. Second parameter lets to inherit access data from other existing rolepublic function allow( string $roleName, string $componentName, mixed $access, mixed $func = null ): void;
public function deny( string $roleName, string $componentName, mixed $access, mixed $func = null ): void;
public function isAllowed( mixed $roleName, mixed $componentName, string $access, array $parameters = null ): bool;
Class Phalcon\Acl\Adapter\Memory
| Namespace | Phalcon\Acl\Adapter | | Uses | Phalcon\Acl\Enum, Phalcon\Acl\Role, Phalcon\Acl\RoleInterface, Phalcon\Acl\Component, Phalcon\Acl\Exception, Phalcon\Events\Manager, Phalcon\Acl\RoleAware, Phalcon\Acl\ComponentAware, Phalcon\Acl\ComponentInterface, ReflectionFunction | | Extends | AbstractAdapter |
Manages ACL lists in memory
$acl = new \Phalcon\Acl\Adapter\Memory();
$acl->setDefaultAction(
\Phalcon\Acl\Enum::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 components
$privateComponents = [
"companies" => ["index", "search", "new", "edit", "save", "create", "delete"],
"products" => ["index", "search", "new", "edit", "save", "create", "delete"],
"invoices" => ["index", "profile"],
];
foreach ($privateComponents as $componentName => $actions) {
$acl->addComponent(
new \Phalcon\Acl\Component($componentName),
$actions
);
}
// Public area components
$publicComponents = [
"index" => ["index"],
"about" => ["index"],
"session" => ["index", "register", "start", "end"],
"contact" => ["index", "send"],
];
foreach ($publicComponents as $componentName => $actions) {
$acl->addComponent(
new \Phalcon\Acl\Component($componentName),
$actions
);
}
// Grant access to public areas to both users and guests
foreach ($roles as $role) {
foreach ($publicComponents as $component => $actions) {
$acl->allow($role->getName(), $component, "*");
}
}
// Grant access to private area to role Users
foreach ($privateComponents as $component => $actions) {
foreach ($actions as $action) {
$acl->allow("Users", $component, $action);
}
}
Properties¶
/**
* Access
*
* @var mixed
*/
protected access;
/**
* Access List
*
* @var mixed
*/
protected accessList;
/**
* Returns latest function used to acquire access
*
* @var mixed
*/
protected activeFunction;
/**
* Returns number of additional arguments(excluding role and resource) for active function
*
* @var int
*/
protected activeFunctionCustomArgumentsCount = 0;
/**
* Returns latest key used to acquire access
*
* @var string|null
*/
protected activeKey;
/**
* Components
*
* @var mixed
*/
protected components;
/**
* Component Names
*
* @var mixed
*/
protected componentsNames;
/**
* Function List
*
* @var mixed
*/
protected func;
/**
* Default action for no arguments is allow
*
* @var mixed
*/
protected noArgumentsDefaultAction;
/**
* Roles
*
* @var mixed
*/
protected roles;
/**
* Role Inherits
*
* @var mixed
*/
protected roleInherits;
/**
* Roles Names
*
* @var mixed
*/
protected rolesNames;
Methods¶
Phalcon\Acl\Adapter\Memory constructor Adds a component to the ACL listAccess names can be a particular action, by example search, update, delete, etc or a list of them
Example:
// Add a component to the the list allowing access to an action
$acl->addComponent(
new Phalcon\Acl\Component("customers"),
"search"
);
$acl->addComponent("customers", "search");
// Add a component with an access list
$acl->addComponent(
new Phalcon\Acl\Component("customers"),
[
"create",
"search",
]
);
$acl->addComponent(
"customers",
[
"create",
"search",
]
);
$acl->addRole("administrator", "consultant");
$acl->addRole("administrator", ["consultant", "consultant2"]);
$acl->addRole(
new Phalcon\Acl\Role("administrator"),
"consultant"
);
$acl->addRole("administrator", "consultant");
$acl->addRole("administrator", ["consultant", "consultant2"]);
public function allow( string $roleName, string $componentName, mixed $access, mixed $func = null ): void;
*
as wildcard // 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 component
$acl->allow("*", "*", "browse");
```php
public function deny( string $roleName, string $componentName, mixed $access, mixed $func = null ): void;
*
as wildcard // 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 component
$acl->deny("*", "*", "browse");
isAllowed
action if a func
(callable) exists for accessKey
Return an array with every role registered in the list public function isAllowed( mixed $roleName, mixed $componentName, string $access, array $parameters = null ): bool;
// Does andres have access to the customers component to create?
$acl->isAllowed("andres", "Products", "create");
// Do guests have access to any component to edit?
$acl->isAllowed("guests", "*", "edit");
Phalcon\Enum::ALLOW
or Phalcon\Enum::DENY
) for no arguments provided in isAllowed action if there exists func for accessKey Class Phalcon\Acl\Component
| Namespace | Phalcon\Acl | | Implements | ComponentInterface |
This class defines component entity and its description
Properties¶
/**
* Component description
*
* @var string
*/
private description;
/**
* Component name
*
* @var string
*/
private name;
Methods¶
Phalcon\Acl\Component constructorInterface Phalcon\Acl\ComponentAware
| Namespace | Phalcon\Acl |
Interface for classes which could be used in allow method as RESOURCE
Methods¶
Returns component nameInterface Phalcon\Acl\ComponentInterface
| Namespace | Phalcon\Acl |
Interface for Phalcon\Acl\Component
Methods¶
Magic method __toString Returns component description Returns the component nameClass Phalcon\Acl\Enum
| Namespace | Phalcon\Acl |
Constants for Phalcon\Acl\Adapter adapters
Constants¶
Class Phalcon\Acl\Exception
| Namespace | Phalcon\Acl | | Extends | \Phalcon\Exception |
Class for exceptions thrown by Phalcon\Acl
Class Phalcon\Acl\Role
| Namespace | Phalcon\Acl | | Implements | RoleInterface |
This class defines role entity and its description
Properties¶
/**
* Role name
*
* @var string
*/
private name;
/**
* Role description
*
* @var string
*/
private description;
Methods¶
Phalcon\Acl\Role constructorInterface Phalcon\Acl\RoleAware
| Namespace | Phalcon\Acl |
Interface for classes which could be used in allow method as ROLE
Methods¶
Returns role nameInterface Phalcon\Acl\RoleInterface
| Namespace | Phalcon\Acl |
Interface for Phalcon\Acl\Role