Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

Helper/Security/Acl/Permission/PermissionMap.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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

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.

Loading history...
78
     */
79
    public function getPossiblePermissions()
80
    {
81
        return array_keys($this->map);
82
    }
83
84
    /**
85
     * Returns a new instance of the MaskBuilder used in the permissionMap.
86
     *
87
     * @return MaskBuilderInterface
88
     */
89
    public function getMaskBuilder()
90
    {
91
        return new MaskBuilder();
92
    }
93
}
94