Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Acl_Role_Registry Class Reference
Inheritance diagram for Zend_Acl_Role_Registry:
Registry

Public Member Functions

 add (Zend_Acl_Role_Interface $role, $parents=null)
 
 get ($role)
 
 has ($role)
 
 getParents ($role)
 
 inherits ($role, $inherit, $onlyParents=false)
 
 remove ($role)
 
 removeAll ()
 
 getRoles ()
 

Protected Attributes

 $_roles = array()
 

Detailed Description

Definition at line 35 of file Registry.php.

Member Function Documentation

◆ add()

add ( Zend_Acl_Role_Interface  $role,
  $parents = null 
)

Adds a Role having an identifier unique to the registry

The $parents parameter may be a reference to, or the string identifier for, a Role existing in the registry, or $parents may be passed as an array of these - mixing string identifiers and objects is ok - to indicate the Roles from which the newly added Role will directly inherit.

In order to resolve potential ambiguities with conflicting rules inherited from different parents, the most recently added parent takes precedence over parents that were previously added. In other words, the first parent added will have the least priority, and the last parent added will have the highest priority.

Parameters
Zend_Acl_Role_Interface$role
Zend_Acl_Role_Interface | string | array$parents
Exceptions
Zend_Acl_Role_Registry_Exception
Returns
Zend_Acl_Role_Registry Provides a fluent interface
See also
Zend_Acl_Role_Registry_Exception
Zend_Acl_Role_Registry_Exception

Definition at line 63 of file Registry.php.

64  {
65  $roleId = $role->getRoleId();
66 
67  if ($this->has($roleId)) {
71  #require_once 'Zend/Acl/Role/Registry/Exception.php';
72  throw new Zend_Acl_Role_Registry_Exception("Role id '$roleId' already exists in the registry");
73  }
74 
75  $roleParents = array();
76 
77  if (null !== $parents) {
78  if (!is_array($parents)) {
79  $parents = array($parents);
80  }
84  #require_once 'Zend/Acl/Role/Registry/Exception.php';
85  foreach ($parents as $parent) {
86  try {
87  if ($parent instanceof Zend_Acl_Role_Interface) {
88  $roleParentId = $parent->getRoleId();
89  } else {
90  $roleParentId = $parent;
91  }
92  $roleParent = $this->get($roleParentId);
94  throw new Zend_Acl_Role_Registry_Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
95  }
96  $roleParents[$roleParentId] = $roleParent;
97  $this->_roles[$roleParentId]['children'][$roleId] = $role;
98  }
99  }
100 
101  $this->_roles[$roleId] = array(
102  'instance' => $role,
103  'parents' => $roleParents,
104  'children' => array()
105  );
106 
107  return $this;
108  }
$roleId
Definition: webapi_user.php:22

◆ get()

get (   $role)

Returns the identified Role

The $role parameter can either be a Role or a Role identifier.

Parameters
Zend_Acl_Role_Interface | string$role
Exceptions
Zend_Acl_Role_Registry_Exception
Returns
Zend_Acl_Role_Interface
See also
Zend_Acl_Role_Registry_Exception

Definition at line 119 of file Registry.php.

120  {
121  if ($role instanceof Zend_Acl_Role_Interface) {
122  $roleId = $role->getRoleId();
123  } else {
124  $roleId = (string) $role;
125  }
126 
127  if (!$this->has($role)) {
131  #require_once 'Zend/Acl/Role/Registry/Exception.php';
132  throw new Zend_Acl_Role_Registry_Exception("Role '$roleId' not found");
133  }
134 
135  return $this->_roles[$roleId]['instance'];
136  }
$roleId
Definition: webapi_user.php:22

◆ getParents()

getParents (   $role)

Returns an array of an existing Role's parents

The array keys are the identifiers of the parent Roles, and the values are the parent Role instances. The parent Roles are ordered in this array by ascending priority. The highest priority parent Role, last in the array, corresponds with the parent Role most recently added.

If the Role does not have any parents, then an empty array is returned.

Parameters
Zend_Acl_Role_Interface | string$role@uses Zend_Acl_Role_Registry::get()
Returns
array

Definition at line 171 of file Registry.php.

172  {
173  $roleId = $this->get($role)->getRoleId();
174 
175  return $this->_roles[$roleId]['parents'];
176  }
$roleId
Definition: webapi_user.php:22

◆ getRoles()

getRoles ( )

Definition at line 266 of file Registry.php.

267  {
268  return $this->_roles;
269  }

◆ has()

has (   $role)

Returns true if and only if the Role exists in the registry

The $role parameter can either be a Role or a Role identifier.

Parameters
Zend_Acl_Role_Interface | string$role
Returns
boolean

Definition at line 146 of file Registry.php.

147  {
148  if ($role instanceof Zend_Acl_Role_Interface) {
149  $roleId = $role->getRoleId();
150  } else {
151  $roleId = (string) $role;
152  }
153 
154  return isset($this->_roles[$roleId]);
155  }
$roleId
Definition: webapi_user.php:22

◆ inherits()

inherits (   $role,
  $inherit,
  $onlyParents = false 
)

Returns true if and only if $role inherits from $inherit

Both parameters may be either a Role or a Role identifier. If $onlyParents is true, then $role must inherit directly from $inherit in order to return true. By default, this method looks through the entire inheritance DAG to determine whether $role inherits from $inherit through its ancestor Roles.

Parameters
Zend_Acl_Role_Interface | string$role
Zend_Acl_Role_Interface | string$inherit
boolean$onlyParents
Exceptions
Zend_Acl_Role_Registry_Exception
Returns
boolean
See also
Zend_Acl_Role_Registry_Exception

Definition at line 193 of file Registry.php.

194  {
198  #require_once 'Zend/Acl/Role/Registry/Exception.php';
199  try {
200  $roleId = $this->get($role)->getRoleId();
201  $inheritId = $this->get($inherit)->getRoleId();
202  } catch (Zend_Acl_Role_Registry_Exception $e) {
203  throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
204  }
205 
206  $inherits = isset($this->_roles[$roleId]['parents'][$inheritId]);
207 
208  if ($inherits || $onlyParents) {
209  return $inherits;
210  }
211 
212  foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
213  if ($this->inherits($parentId, $inheritId)) {
214  return true;
215  }
216  }
217 
218  return false;
219  }
inherits($role, $inherit, $onlyParents=false)
Definition: Registry.php:193
$roleId
Definition: webapi_user.php:22

◆ remove()

remove (   $role)

Removes the Role from the registry

The $role parameter can either be a Role or a Role identifier.

Parameters
Zend_Acl_Role_Interface | string$role
Exceptions
Zend_Acl_Role_Registry_Exception
Returns
Zend_Acl_Role_Registry Provides a fluent interface
See also
Zend_Acl_Role_Registry_Exception

Definition at line 230 of file Registry.php.

231  {
235  #require_once 'Zend/Acl/Role/Registry/Exception.php';
236  try {
237  $roleId = $this->get($role)->getRoleId();
238  } catch (Zend_Acl_Role_Registry_Exception $e) {
239  throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
240  }
241 
242  foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
243  unset($this->_roles[$childId]['parents'][$roleId]);
244  }
245  foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
246  unset($this->_roles[$parentId]['children'][$roleId]);
247  }
248 
249  unset($this->_roles[$roleId]);
250 
251  return $this;
252  }
$roleId
Definition: webapi_user.php:22

◆ removeAll()

removeAll ( )

Removes all Roles from the registry

Returns
Zend_Acl_Role_Registry Provides a fluent interface

Definition at line 259 of file Registry.php.

260  {
261  $this->_roles = array();
262 
263  return $this;
264  }

Field Documentation

◆ $_roles

$_roles = array()
protected

Definition at line 42 of file Registry.php.


The documentation for this class was generated from the following file: