Hoa central
Service.php
Go to the documentation of this file.
1 <?php
2 
37 namespace Hoa\Acl;
38 
47 class Service
48 {
54  protected $serviceId = null;
55 
61  protected $serviceLabel = null;
62 
68  protected $users = [];
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 addUser($users = [])
94  {
95  if (!is_array($users)) {
96  $users = [$users];
97  }
98 
99  foreach ($users as $user) {
100  if ($user instanceof User) {
101  $user = $user->getId();
102  }
103 
104  if (true === $this->userExists($user)) {
105  continue;
106  }
107 
108  $this->users[$user] = true;
109  }
110 
111  return $this->getUsers();
112  }
113 
120  public function deleteUser($users = [])
121  {
122  $users = (array) $users;
123 
124  foreach ($users as $user) {
125  if ($user instanceof User) {
126  $user = $user->getId();
127  }
128 
129  if (false === $this->userExists($user)) {
130  continue;
131  }
132 
133  unset($this->users[$user]);
134  }
135 
136  return $this->getUsers();
137  }
138 
145  public function userExists($userId)
146  {
147  if ($userId instanceof User) {
148  $userId = $userId->getId();
149  }
150 
151  return isset($this->users[$userId]);
152  }
153 
159  public function getUsers()
160  {
161  return array_keys($this->users);
162  }
163 
170  protected function setId($id)
171  {
172  $old = $this->serviceId;
173  $this->serviceId = $id;
174 
175  return $old;
176  }
177 
184  public function setLabel($label)
185  {
186  $old = $this->serviceLabel;
187  $this->serviceLabel = $label;
188 
189  return $old;
190  }
191 
197  public function getId()
198  {
199  return $this->serviceId;
200  }
201 
207  public function getLabel()
208  {
209  return $this->serviceLabel;
210  }
211 }
Definition: Acl.php:37
userExists($userId)
Definition: Service.php:145
deleteUser($users=[])
Definition: Service.php:120
setLabel($label)
Definition: Service.php:184
addUser($users=[])
Definition: Service.php:93
__construct($id, $label=null)
Definition: Service.php:79