|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\Security\Acl\Domain; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; |
|
|
15 |
use Symfony\Component\Security\Core\Role\Role; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* A SecurityIdentity implementation for roles |
|
|
19 |
* |
|
|
20 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
21 |
*/ |
|
|
22 |
final class RoleSecurityIdentity implements SecurityIdentityInterface |
|
|
23 |
{ |
|
|
24 |
private $role; |
|
|
25 |
|
|
|
26 |
/** |
|
|
27 |
* Constructor |
|
|
28 |
* |
|
|
29 |
* @param mixed $role a Role instance, or its string representation |
|
|
30 |
* @return void |
|
|
31 |
*/ |
|
|
32 |
public function __construct($role) |
|
|
33 |
{ |
|
|
34 |
if ($role instanceof Role) { |
|
|
35 |
$role = $role->getRole(); |
|
|
36 |
} |
|
|
37 |
|
|
|
38 |
$this->role = $role; |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
/** |
|
|
42 |
* Returns the role name |
|
|
43 |
* |
|
|
44 |
* @return string |
|
|
45 |
*/ |
|
|
46 |
public function getRole() |
|
|
47 |
{ |
|
|
48 |
return $this->role; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
/** |
|
|
52 |
* {@inheritDoc} |
|
|
53 |
*/ |
|
|
54 |
public function equals(SecurityIdentityInterface $sid) |
|
|
55 |
{ |
|
|
56 |
if (!$sid instanceof RoleSecurityIdentity) { |
|
|
57 |
return false; |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
return $this->role === $sid->getRole(); |
|
|
61 |
} |
|
|
62 |
|
|
|
63 |
/** |
|
|
64 |
* Returns a textual representation of this security identity. |
|
|
65 |
* |
|
|
66 |
* This is solely used for debugging purposes, not to make an equality decision. |
|
|
67 |
* |
|
|
68 |
* @return string |
|
|
69 |
*/ |
|
|
70 |
public function __toString() |
|
|
71 |
{ |
|
|
72 |
return sprintf('RoleSecurityIdentity(%s)', $this->role); |
|
|
73 |
} |
|
|
74 |
} |