|
16 | 16 | * This class represents a location in the repository. |
17 | 17 | * |
18 | 18 | * @property-read \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo calls getContentInfo() |
19 | | - * @property-read int $contentId calls getContentInfo()->id |
20 | | - * @property-read int $id the id of the location |
| 19 | + * @property-read int $contentId @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getContentId()} instead. |
| 20 | + * @property-read int $id @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getId()} instead. |
21 | 21 | * @property-read int $priority Position of the Location among its siblings when sorted using priority |
22 | | - * @property-read bool $hidden Indicates that the Location entity is hidden (explicitly or hidden by content). |
23 | | - * @property-read bool $invisible Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by its Content or an ancestor Location |
| 22 | + * @property-read bool $hidden @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::isHidden()} instead. |
| 23 | + * @property-read bool $invisible @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::isInvisible()} instead. |
24 | 24 | * @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden. |
25 | 25 | * @property-read string $remoteId a global unique id of the content object |
26 | 26 | * @property-read int $parentLocationId the id of the parent location |
27 | | - * @property-read string $pathString @deprecated use {@see Location::getPathString()} instead. |
28 | | - * @property-read array $path Same as $pathString but as array, e.g. [ 1, 2, 4, 23 ] |
29 | | - * @property-read int $depth Depth location has in the location tree |
| 27 | + * @property-read string $pathString @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getPathString()} instead. |
| 28 | + * @property-read array $path @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getPath()} instead. |
| 29 | + * @property-read int $depth @deprecated 4.6.7 accessing magic getter is deprecated and will be removed in 5.0.0. Use {@see Location::getDepth()} instead. |
30 | 30 | * @property-read int $sortField Specifies which property the child locations should be sorted on. Valid values are found at {@link Location::SORT_FIELD_*} |
31 | 31 | * @property-read int $sortOrder Specifies whether the sort order should be ascending or descending. Valid values are {@link Location::SORT_ORDER_*} |
32 | 32 | */ |
@@ -158,6 +158,13 @@ abstract class Location extends ValueObject |
158 | 158 | */ |
159 | 159 | protected $pathString; |
160 | 160 |
|
| 161 | + /** |
| 162 | + * Same as {@see Location::$pathString} but as array, e.g.: <code>[ '1', '2', '4', '23' ]</code>. |
| 163 | + * |
| 164 | + * @var string[] |
| 165 | + */ |
| 166 | + protected array $path; |
| 167 | + |
161 | 168 | /** |
162 | 169 | * Depth location has in the location tree. |
163 | 170 | * |
@@ -194,12 +201,22 @@ abstract class Location extends ValueObject |
194 | 201 | abstract public function getContentInfo(): ContentInfo; |
195 | 202 |
|
196 | 203 | /** |
197 | | - * Return the parent location of of this location. |
| 204 | + * Return the parent location of this location. |
198 | 205 | * |
199 | 206 | * @return \Ibexa\Contracts\Core\Repository\Values\Content\Location|null |
200 | 207 | */ |
201 | 208 | abstract public function getParentLocation(): ?Location; |
202 | 209 |
|
| 210 | + public function getId(): int |
| 211 | + { |
| 212 | + return $this->id; |
| 213 | + } |
| 214 | + |
| 215 | + public function getContentId(): int |
| 216 | + { |
| 217 | + return $this->getContentInfo()->getId(); |
| 218 | + } |
| 219 | + |
203 | 220 | /** |
204 | 221 | * Returns true if current location is a draft. |
205 | 222 | * |
@@ -248,6 +265,62 @@ public function getPathString(): string |
248 | 265 | { |
249 | 266 | return $this->pathString; |
250 | 267 | } |
| 268 | + |
| 269 | + /** |
| 270 | + * Same as {@see Location::getPathString()} but as array, e.g.: <code>[ '1', '2', '4', '23' ]</code>. |
| 271 | + * |
| 272 | + * @return string[] |
| 273 | + */ |
| 274 | + public function getPath(): array |
| 275 | + { |
| 276 | + if (isset($this->path)) { |
| 277 | + return $this->path; |
| 278 | + } |
| 279 | + |
| 280 | + $pathString = trim($this->pathString ?? '', '/'); |
| 281 | + |
| 282 | + return $this->path = !empty($pathString) ? explode('/', $pathString) : []; |
| 283 | + } |
| 284 | + |
| 285 | + /** |
| 286 | + * Indicates that the Location is not visible, being either marked as hidden itself, or implicitly hidden by |
| 287 | + * its Content or an ancestor Location. |
| 288 | + */ |
| 289 | + public function isInvisible(): bool |
| 290 | + { |
| 291 | + return $this->invisible; |
| 292 | + } |
| 293 | + |
| 294 | + /** |
| 295 | + * Indicates that the Location is hidden either explicitly or by content. |
| 296 | + */ |
| 297 | + public function isHidden(): bool |
| 298 | + { |
| 299 | + return $this->hidden; |
| 300 | + } |
| 301 | + |
| 302 | + public function getDepth(): int |
| 303 | + { |
| 304 | + return $this->depth; |
| 305 | + } |
| 306 | + |
| 307 | + public function __isset($property) |
| 308 | + { |
| 309 | + if ($property === 'path') { |
| 310 | + return true; |
| 311 | + } |
| 312 | + |
| 313 | + return parent::__isset($property); |
| 314 | + } |
| 315 | + |
| 316 | + public function __get($property) |
| 317 | + { |
| 318 | + if ($property === 'path') { |
| 319 | + return $this->getPath(); |
| 320 | + } |
| 321 | + |
| 322 | + return parent::__get($property); |
| 323 | + } |
251 | 324 | } |
252 | 325 |
|
253 | 326 | class_alias(Location::class, 'eZ\Publish\API\Repository\Values\Content\Location'); |
0 commit comments