Hoa central
Group.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Acl;
38 
39 use Hoa\Graph;
40 
50 class Group implements Graph\IGraph\Node
51 {
57  protected $groupId = null;
58 
64  protected $groupLabel = null;
65 
71  protected $permissions = [];
72 
73 
74 
82  public function __construct($id, $label = null)
83  {
84  $this->setId($id);
85  $this->setLabel($label);
86 
87  return;
88  }
89 
97  public function addPermission($permissions = [])
98  {
99  if (!is_array($permissions)) {
101  }
102 
103  foreach ($permissions as $permission) {
104  if (!($permission instanceof Permission)) {
105  throw new Exception(
106  'Permission %s must be an instance of \Hoa\Acl\Permission',
107  0,
108  $permission
109  );
110  }
111 
112  if (true === $this->permissionExists($permission->getId())) {
113  continue;
114  }
115 
116  $this->permissions[$permission->getId()] = $permission;
117  }
118 
119  return $this->getPermissions();
120  }
121 
129  public function deletePermission($permissions = [])
130  {
131  if (!is_array($permissions)) {
133  }
134 
135  foreach ($permissions as $permission) {
136  if ($permission instanceof Permission) {
137  $permission = $permission->getId();
138  }
139 
140  if (false === $this->permissionExists($permission)) {
141  continue;
142  }
143 
144  unset($this->permissions[$permission]);
145  }
146 
147  return $this->getPermissions();
148  }
149 
156  public function permissionExists($permissionId)
157  {
158  return isset($this->permissions[$permissionId]);
159  }
160 
166  public function getPermissions()
167  {
168  return $this->permissions;
169  }
170 
177  protected function setId($id)
178  {
179  $old = $this->groupId;
180  $this->groupId = $id;
181 
182  return $old;
183  }
184 
191  public function setLabel($label)
192  {
193  $old = $this->groupLabel;
194  $this->groupLabel = $label;
195 
196  return $old;
197  }
198 
204  public function getId()
205  {
206  return $this->groupId;
207  }
208 
214  public function getLabel()
215  {
216  return $this->groupLabel;
217  }
218 
225  public function getNodeId()
226  {
227  return $this->getId();
228  }
229 }
getPermissions()
Definition: Group.php:166
Definition: Acl.php:37
permissionExists($permissionId)
Definition: Group.php:156
setId($id)
Definition: Group.php:177
__construct($id, $label=null)
Definition: Group.php:82
deletePermission($permissions=[])
Definition: Group.php:129
addPermission($permissions=[])
Definition: Group.php:97
setLabel($label)
Definition: Group.php:191