1 | <?php |
||
49 | class Thing implements ThingInterface |
||
50 | { |
||
51 | /** |
||
52 | * Resource type |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $type; |
||
57 | /** |
||
58 | * Resource vocabulary |
||
59 | * |
||
60 | * @var VocabularyInterface |
||
61 | */ |
||
62 | protected $vocabulary; |
||
63 | /** |
||
64 | * Resource ID |
||
65 | * |
||
66 | * @var string|null |
||
67 | */ |
||
68 | protected $resourceId = null; |
||
69 | /** |
||
70 | * Child things |
||
71 | * |
||
72 | * @var Thing[] |
||
73 | */ |
||
74 | protected $children = []; |
||
75 | /** |
||
76 | * Property |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | protected $properties = []; |
||
81 | |||
82 | /** |
||
83 | * Thing constructor |
||
84 | * |
||
85 | * @param string $type Resource type |
||
86 | * @param VocabularyInterface $vocabulary Vocabulary in use |
||
87 | * @param null|string $resourceId Resource id |
||
88 | */ |
||
89 | 7 | public function __construct($type, VocabularyInterface $vocabulary, $resourceId = null) |
|
103 | |||
104 | /** |
||
105 | * Return the resource type |
||
106 | * |
||
107 | * @return string Resource type |
||
108 | */ |
||
109 | 1 | public function getType() |
|
113 | |||
114 | /** |
||
115 | * Return the vocabulary in use |
||
116 | * |
||
117 | * @return VocabularyInterface Vocabulary |
||
118 | */ |
||
119 | 1 | public function getVocabulary() |
|
123 | |||
124 | /** |
||
125 | * Return the resource ID |
||
126 | * |
||
127 | * @return null|string Resource ID |
||
128 | */ |
||
129 | 2 | public function getResourceId() |
|
130 | { |
||
131 | 2 | return $this->resourceId; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * Add a property value |
||
136 | * |
||
137 | * @param string $name Property name |
||
138 | * @param mixed $value Property value |
||
139 | * @return Thing Self reference |
||
140 | */ |
||
141 | 2 | public function addProperty($name, $value) |
|
155 | |||
156 | /** |
||
157 | * Validate a property name |
||
158 | * |
||
159 | * @param string $name Property name |
||
160 | * @return string Sanitized property name |
||
161 | * @throws RuntimeException If the property name is invalid |
||
162 | */ |
||
163 | 3 | protected function validatePropertyName($name) |
|
176 | |||
177 | /** |
||
178 | * Return all properties |
||
179 | * |
||
180 | * @return array Properties |
||
181 | */ |
||
182 | 2 | public function getProperties() |
|
186 | |||
187 | /** |
||
188 | * Return the values of a single property |
||
189 | * |
||
190 | * @param string $name Property name |
||
191 | * @return array Property values |
||
192 | * @throws OutOfBoundsException If the property name is unknown |
||
193 | */ |
||
194 | 2 | public function getProperty($name) |
|
208 | |||
209 | /** |
||
210 | * Add a child |
||
211 | * |
||
212 | * @param ThingInterface $child Child |
||
213 | * @return Thing Self reference |
||
214 | */ |
||
215 | 1 | public function addChild(ThingInterface $child) |
|
220 | |||
221 | /** |
||
222 | * Return all children |
||
223 | * |
||
224 | * @return Thing[] Children |
||
225 | */ |
||
226 | 2 | public function getChildren() |
|
230 | } |
||
231 |