1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* IResource.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license http://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec http://www.ipublikuj.eu |
8
|
|
|
* @package iPublikuj:Permissions! |
9
|
|
|
* @subpackage Entities |
10
|
|
|
* @since 2.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 30.11.16 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\Permissions\Entities; |
18
|
|
|
|
19
|
|
|
use Nette; |
20
|
|
|
|
21
|
1 |
|
class Resource extends Nette\Object implements IResource |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var IResource|NULL |
30
|
|
|
*/ |
31
|
|
|
protected $parent; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var IResource[] |
35
|
|
|
*/ |
36
|
|
|
protected $children; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string|NULL |
40
|
|
|
*/ |
41
|
|
|
protected $name; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string|NULL |
45
|
|
|
*/ |
46
|
|
|
protected $comment; |
47
|
|
|
|
48
|
|
|
public function __construct(string $id) |
49
|
|
|
{ |
50
|
1 |
|
$this->id = $id; |
51
|
|
|
|
52
|
1 |
|
$this->children = new \SplObjectStorage(); |
|
|
|
|
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function setParent(IResource $parent = NULL) |
59
|
|
|
{ |
60
|
|
|
$this->parent = $parent; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
public function getParent() |
67
|
|
|
{ |
68
|
1 |
|
return $this->parent; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
|
|
public function setChildren(array $resources) |
75
|
|
|
{ |
76
|
|
|
$this->children = new \SplObjectStorage(); |
|
|
|
|
77
|
|
|
|
78
|
|
|
foreach ($resources as $child) { |
79
|
|
|
if ($child instanceof IResource) { |
80
|
|
|
$this->children->attach($child); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function addChild(IResource $resource) |
89
|
|
|
{ |
90
|
|
|
if (!$this->children->contains($resource)) { |
|
|
|
|
91
|
|
|
$this->children->attach($resource); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
|
View Code Duplication |
public function getChildren() |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$children = []; |
101
|
|
|
|
102
|
|
|
$this->children->rewind(); |
|
|
|
|
103
|
|
|
|
104
|
|
|
while ($this->children->valid()) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
$children[] = $this->children->current(); |
|
|
|
|
107
|
|
|
$this->children->next(); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $children; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function getResourceId() : string |
117
|
|
|
{ |
118
|
1 |
|
return $this->id; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* {@inheritdoc} |
123
|
|
|
*/ |
124
|
|
|
public function setName(string $name) |
125
|
|
|
{ |
126
|
|
|
$this->name = $name; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritdoc} |
131
|
|
|
*/ |
132
|
|
|
public function getName() |
133
|
|
|
{ |
134
|
|
|
return $this->name; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
|
|
public function setComment(string $comment) |
141
|
|
|
{ |
142
|
|
|
$this->comment = $comment; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* {@inheritdoc} |
147
|
|
|
*/ |
148
|
|
|
public function getComment() |
149
|
|
|
{ |
150
|
|
|
return $this->comment; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Convert resource object to string |
155
|
|
|
* |
156
|
|
|
* @return string |
157
|
|
|
*/ |
158
|
|
|
public function __toString() |
159
|
|
|
{ |
160
|
1 |
|
return $this->id; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..