Hoa central
User.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Acl;
38 
47 class User
48 {
54  protected $userId = null;
55 
61  protected $userLabel = null;
62 
68  protected $groups = [];
69 
70 
71 
79  public function __construct($id, $label = null)
80  {
81  $this->setId($id);
82  $this->setLabel($label);
83 
84  return;
85  }
86 
93  public function addGroup($groups = [])
94  {
95  if (!is_array($groups)) {
96  $groups = [$groups];
97  }
98 
99  foreach ($groups as $group) {
100  if ($group instanceof Group) {
101  $group = $group->getId();
102  }
103 
104  if (true === $this->groupExists($group)) {
105  continue;
106  }
107 
108  $this->groups[$group] = true;
109  }
110 
111  return $this->getGroups();
112  }
113 
120  public function deleteGroup($groups = [])
121  {
122  if (!is_array($groups)) {
123  $groups = [$groups];
124  }
125 
126  foreach ($groups as $group) {
127  if ($group instanceof Group) {
128  $group = $group->getId();
129  }
130 
131  if (false === $this->groupExists($group)) {
132  continue;
133  }
134 
135  unset($this->groups[$group]);
136  }
137 
138  return $this->getGroups();
139  }
140 
147  public function groupExists($groupId)
148  {
149  if ($groupId instanceof Group) {
150  $groupId = $groupId->getId();
151  }
152 
153  return isset($this->groups[$groupId]);
154  }
155 
161  public function getGroups()
162  {
163  return array_keys($this->groups);
164  }
165 
172  protected function setId($id)
173  {
174  $old = $this->userId;
175  $this->userId = $id;
176 
177  return $old;
178  }
179 
186  public function setLabel($label)
187  {
188  $old = $this->userLabel;
189  $this->userLabel = $label;
190 
191  return $old;
192  }
193 
199  public function getId()
200  {
201  return $this->userId;
202  }
203 
209  public function getLabel()
210  {
211  return $this->userLabel;
212  }
213 }
groupExists($groupId)
Definition: User.php:147
Definition: Acl.php:37
getGroups()
Definition: User.php:161
setLabel($label)
Definition: User.php:186
__construct($id, $label=null)
Definition: User.php:79
deleteGroup($groups=[])
Definition: User.php:120
addGroup($groups=[])
Definition: User.php:93
setId($id)
Definition: User.php:172
getLabel()
Definition: User.php:209