Phalcon acl
注意
所有类都以前缀命名Phalcon
Acl\Adapter\AbstractAdapter
¶
  -  
命名空间
Phalcon\Acl\Adapter
 -  
使用
Phalcon\Acl\EnumPhalcon\Events\AbstractEventsAwarePhalcon\Events\EventsAwareInterface
 -  
继承
AbstractEventsAware -  
实现
AdapterInterfaceEventsAwareInterface
 
Phalcon\Acl 适配器的适配器
属性¶
/**
 * Access Granted
 *
 * @var bool
 */
protected $accessGranted = false;
/**
 * Active access which the list is checking if some role can access it
 *
 * @var string|null
 */
protected $activeAccess;
/**
 * Component which the list is checking if some role can access it
 *
 * @var string|null
 */
protected $activeComponent;
/**
 * Role which the list is checking if it's allowed to certain
 * component/access
 *
 * @var string|null
 */
protected $activeRole;
/**
 * Default access
 *
 * @var int
 */
protected $defaultAccess;
方法¶
列表正在检查某个角色是否可以访问的活动访问权限 列表正在检查某个角色是否可以访问的组件 列表正在检查的角色,以确定其是否允许访问特定的组件/访问权限 返回默认的 ACL 访问级别 设置默认访问级别 (Phalcon\Acl\Enum::ALLOW 或 Phalcon\Acl\Enum::DENY)Acl\Adapter\AdapterInterface
¶
  -  
命名空间
Phalcon\Acl\Adapter
 -  
使用
Phalcon\Acl\ComponentInterfacePhalcon\Acl\RoleInterface
 -  
继承
 -  
实现
 
Phalcon\Acl 适配器的接口
方法¶
向 ACL 列表中添加一个组件访问名称可以是特定的动作,例如搜索、更新、删除等,或者它们的列表
向组件添加访问权限 检查一个角色是否继承自另一个现有角色 向 ACL 列表中添加一个角色。第二个参数允许从其他现有角色继承访问数据public 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;
Acl\Adapter\Memory¶
-  
命名空间
Phalcon\Acl\Adapter
 -  
使用
Phalcon\Acl\ComponentPhalcon\Acl\ComponentAwareInterfacePhalcon\Acl\ComponentInterfacePhalcon\Acl\EnumPhalcon\Acl\ExceptionPhalcon\Acl\RolePhalcon\Acl\RoleAwareInterfacePhalcon\Acl\RoleInterfaceReflectionClassReflectionFunction
 -  
继承
AbstractAdapter -  
实现
 
在内存中管理 ACL 列表
$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);
    }
}
属性¶
/**
 * Access
 *
 * @var mixed
 */
protected $access;
/**
 * Access List
 *
 * @var mixed
 */
protected $accessList;
/**
 * Returns the 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 = ;
/**
 * Returns the 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;
方法¶
Phalcon\Acl\Adapter\Memory 构造函数 向 ACL 列表中添加一个组件访问名称可以是特定的动作,例如搜索、更新、删除等,或者它们的列表
示例:
// Add a component to 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;
*作为通配符 // 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");
public function deny( string $roleName, string $componentName, mixed $access, mixed $func = null ): void;
*作为通配符 // 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动作中没有提供参数时的默认 ACL 访问级别,如果func(可调用)存在则适用于accessKey 返回一个包含列表中注册的所有角色的数组 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或Phalcon\Enum::DENY) 对于在 isAllowed 动作中没有提供参数的情况,如果存在针对 accessKey 的 func Acl\Component¶
-  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
ComponentInterface
 
此类定义了组件实体及其描述
属性¶
/**
 * Component description
 *
 * @var string
 */
private $description;
/**
 * Component name
 *
 * @var string
 */
private $name;
方法¶
Phalcon\Acl\Component 构造函数Acl\ComponentAwareInterface
¶
  -  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
 
可在 allow 方法中作为 RESOURCE 使用的类的接口
方法¶
返回组件名称Acl\ComponentInterface
¶
  -  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
 
Phalcon\Acl\Component 的接口
方法¶
魔术方法 __toString 返回组件描述 返回组件名称Acl\Enum¶
-  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
 
Phalcon\Acl\Adapter 适配器的常量
常量¶
Acl\Exception¶
-  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
\Exception -  
实现
 
由 Phalcon\Acl 抛出的异常的类
Acl\Role¶
-  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
RoleInterface
 
此类定义了角色实体及其描述
属性¶
/**
 * Role description
 *
 * @var string
 */
private $description;
/**
 * Role name
 *
 * @var string
 */
private $name;
方法¶
Phalcon\Acl\Role 构造函数Acl\RoleAwareInterface
¶
  -  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
 
可在 allow 方法中作为 ROLE 使用的类的接口
方法¶
返回角色名称Acl\RoleInterface
¶
  -  
命名空间
Phalcon\Acl
 -  
使用
 -  
继承
 -  
实现
 
Phalcon\Acl\Role 的接口