equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the FOSUserBundle package. |
|
5 * |
|
6 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7 * |
|
8 * For the full copyright and license information, please view the LICENSE |
|
9 * file that was distributed with this source code. |
|
10 */ |
|
11 |
|
12 namespace FOS\UserBundle\Model; |
|
13 |
|
14 /** |
|
15 * @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
16 */ |
|
17 abstract class Group implements GroupInterface |
|
18 { |
|
19 protected $id; |
|
20 protected $name; |
|
21 protected $roles; |
|
22 |
|
23 public function __construct($name, $roles = array()) |
|
24 { |
|
25 $this->name = $name; |
|
26 $this->roles = $roles; |
|
27 } |
|
28 |
|
29 public function addRole($role) |
|
30 { |
|
31 if (!$this->hasRole($role)) { |
|
32 $this->roles[] = strtoupper($role); |
|
33 } |
|
34 } |
|
35 |
|
36 public function getId() |
|
37 { |
|
38 return $this->id; |
|
39 } |
|
40 |
|
41 public function getName() |
|
42 { |
|
43 return $this->name; |
|
44 } |
|
45 |
|
46 public function hasRole($role) |
|
47 { |
|
48 return in_array(strtoupper($role), $this->roles, true); |
|
49 } |
|
50 |
|
51 public function getRoles() |
|
52 { |
|
53 return $this->roles; |
|
54 } |
|
55 |
|
56 public function removeRole($role) |
|
57 { |
|
58 if (false !== $key = array_search(strtoupper($role), $this->roles, true)) { |
|
59 unset($this->roles[$key]); |
|
60 $this->roles = array_values($this->roles); |
|
61 } |
|
62 } |
|
63 |
|
64 public function setName($name) |
|
65 { |
|
66 $this->name = $name; |
|
67 } |
|
68 |
|
69 public function setRoles(array $roles) |
|
70 { |
|
71 $this->roles = $roles; |
|
72 } |
|
73 } |