1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\AdminBundle\Helper\Security\Acl\Permission; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Security\Acl\Permission\MaskBuilderInterface; |
6
|
|
|
use Symfony\Component\Security\Acl\Permission\MaskBuilderRetrievalInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* PermissionMap which stores all the possible permissions, this is based on the BasicPermissionMap |
10
|
|
|
*/ |
11
|
|
|
class PermissionMap implements PermissionMapInterface, MaskBuilderRetrievalInterface |
12
|
|
|
{ |
13
|
|
|
const PERMISSION_VIEW = 'VIEW'; |
14
|
|
|
const PERMISSION_EDIT = 'EDIT'; |
15
|
|
|
const PERMISSION_DELETE = 'DELETE'; |
16
|
|
|
const PERMISSION_PUBLISH = 'PUBLISH'; |
17
|
|
|
const PERMISSION_UNPUBLISH = 'UNPUBLISH'; |
18
|
|
|
|
19
|
|
|
private $map = array( |
20
|
|
|
self::PERMISSION_VIEW => array( |
21
|
|
|
MaskBuilder::MASK_VIEW, |
22
|
|
|
), |
23
|
|
|
|
24
|
|
|
self::PERMISSION_EDIT => array( |
25
|
|
|
MaskBuilder::MASK_EDIT, |
26
|
|
|
), |
27
|
|
|
self::PERMISSION_DELETE => array( |
28
|
|
|
MaskBuilder::MASK_DELETE, |
29
|
|
|
), |
30
|
|
|
|
31
|
|
|
self::PERMISSION_PUBLISH => array( |
32
|
|
|
MaskBuilder::MASK_PUBLISH, |
33
|
|
|
), |
34
|
|
|
|
35
|
|
|
self::PERMISSION_UNPUBLISH => array( |
36
|
|
|
MaskBuilder::MASK_UNPUBLISH, |
37
|
|
|
), |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns an array of bitmasks. |
42
|
|
|
* |
43
|
|
|
* The security identity must have been granted access to at least one of |
44
|
|
|
* these bitmasks. |
45
|
|
|
* |
46
|
|
|
* @param string $permission The permission |
47
|
|
|
* @param object|null $object The object |
48
|
|
|
* |
49
|
|
|
* @return array may return null if permission/object combination is not supported |
50
|
|
|
*/ |
51
|
2 |
|
public function getMasks($permission, $object) |
52
|
|
|
{ |
53
|
2 |
|
if (!isset($this->map[$permission])) { |
54
|
1 |
|
return null; |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
return $this->map[$permission]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Whether this map contains the given permission |
62
|
|
|
* |
63
|
|
|
* @param string $permission |
64
|
|
|
* |
65
|
|
|
* @return bool |
66
|
|
|
*/ |
67
|
1 |
|
public function contains($permission) |
68
|
|
|
{ |
69
|
1 |
|
return isset($this->map[$permission]); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the array of permissions. |
74
|
|
|
* |
75
|
|
|
* @return array |
|
|
|
|
76
|
|
|
*/ |
77
|
1 |
|
public function getPossiblePermissions() |
78
|
|
|
{ |
79
|
1 |
|
return array_keys($this->map); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns a new instance of the MaskBuilder used in the permissionMap. |
84
|
|
|
* |
85
|
|
|
* @return MaskBuilderInterface |
86
|
|
|
*/ |
87
|
1 |
|
public function getMaskBuilder() |
88
|
|
|
{ |
89
|
1 |
|
return new MaskBuilder(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.