Completed
Pull Request — master (#120)
by De Cramer
02:35
created

AbstractItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 5
1
<?php
2
3
namespace eXpansion\Bundle\Menu\Model\Menu;
4
5
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
6
7
/**
8
 * Class AbstractItem
9
 *
10
 * @author    de Cramer Oliver<[email protected]>
11
 * @copyright 2017 Smile
12
 * @package eXpansion\Bundle\Menu\Model\Menu
13
 */
14
abstract class AbstractItem implements ItemInterface
15
{
16
    /** @var string */
17
    private $id;
18
19
    /** @var string */
20
    private $path = null;
21
22
    /** @var string */
23
    private $labelId;
24
25
    /** @var string|null */
26
    private $permission;
27
28
    /** @var AdminGroups */
29
    private $adminGroups;
30
31
    /**
32
     * AbstractItem constructor.
33
     *
34
     * @param             $id
35
     * @param             $path
36
     * @param             $labelId
37
     * @param AdminGroups $adminGroups
38
     * @param null        $permission
39
     */
40
    public function __construct($id, $path, $labelId, AdminGroups $adminGroups, $permission = null)
41
    {
42
        $this->id = $id;
43
        $this->path = $path;
44
        $this->labelId = $labelId;
45
        $this->permission = $permission;
46
        $this->adminGroups = $adminGroups;
47
    }
48
49
    /**
50
     * Unique identifier for menu item (needs to be unique in level)
51
     *
52
     * @return string
53
     */
54
    public function getId()
55
    {
56
        return $this->id;
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getPath()
63
    {
64
        return $this->path;
65
    }
66
67
    /**
68
     * Label to be translated to be displayed on the menu.
69
     *
70
     * @return string
71
     */
72
    public function getLabelId()
73
    {
74
        return $this->labelId;
75
    }
76
77
    /**
78
     * Get the permission required to use this menu item.
79
     *
80
     * @return mixed
81
     */
82
    public function permission()
83
    {
84
        return $this->permission;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90
    public function isVisibleFor($login)
91
    {
92
        if (is_null($this->permission)) {
93
            return true;
94
        }
95
96
        return $this->adminGroups->hasPermission($login, $this->permission);
97
    }
98
}
99