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
|
|
|
class Resource implements IResource |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Implement nette smart magic |
25
|
|
|
*/ |
26
|
|
|
use Nette\SmartObject; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $id; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var IResource|NULL |
35
|
|
|
*/ |
36
|
|
|
protected $parent; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var IResource[] |
40
|
|
|
*/ |
41
|
|
|
protected $children; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string|NULL |
45
|
|
|
*/ |
46
|
|
|
protected $name; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string|NULL |
50
|
|
|
*/ |
51
|
|
|
protected $comment; |
52
|
|
|
|
53
|
|
|
public function __construct(string $id) |
54
|
|
|
{ |
55
|
|
|
$this->id = $id; |
56
|
|
|
|
57
|
|
|
$this->children = new \SplObjectStorage(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
|
|
public function setParent(IResource $parent = NULL) |
64
|
|
|
{ |
65
|
|
|
$this->parent = $parent; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function getParent() |
72
|
|
|
{ |
73
|
|
|
return $this->parent; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function setChildren(array $resources) |
80
|
|
|
{ |
81
|
|
|
$this->children = new \SplObjectStorage(); |
|
|
|
|
82
|
|
|
|
83
|
|
|
foreach ($resources as $child) { |
84
|
|
|
if ($child instanceof IResource) { |
85
|
|
|
$this->children->attach($child); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function addChild(IResource $resource) |
94
|
|
|
{ |
95
|
|
|
if (!$this->children->contains($resource)) { |
|
|
|
|
96
|
|
|
$this->children->attach($resource); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function getChildren() |
104
|
|
|
{ |
105
|
|
|
return $this->children; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritdoc} |
110
|
|
|
*/ |
111
|
|
|
public function getResourceId() : string |
112
|
|
|
{ |
113
|
|
|
return $this->id; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
*/ |
119
|
|
|
public function setName(string $name) |
120
|
|
|
{ |
121
|
|
|
$this->name = $name; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritdoc} |
126
|
|
|
*/ |
127
|
|
|
public function getName() |
128
|
|
|
{ |
129
|
|
|
return $this->name; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritdoc} |
134
|
|
|
*/ |
135
|
|
|
public function setComment(string $comment) |
136
|
|
|
{ |
137
|
|
|
$this->comment = $comment; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritdoc} |
142
|
|
|
*/ |
143
|
|
|
public function getComment() |
144
|
|
|
{ |
145
|
|
|
return $this->comment; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Convert resource object to string |
150
|
|
|
* |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function __toString() |
154
|
|
|
{ |
155
|
|
|
return $this->id; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
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..