1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the eZ\Publish\Core\Repository\Values\Content\TrashItem class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Repository\Values\Content; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
|
|
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\TrashItem as APITrashItem; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* this class represents a trash item, which is actually a trashed location. |
16
|
|
|
* |
17
|
|
|
* @internal Meant for internal use by Repository, type hint against API object instead. |
18
|
|
|
*/ |
19
|
|
|
class TrashItem extends APITrashItem |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Content info of the content object of this trash item. |
23
|
|
|
* |
24
|
|
|
* @var \eZ\Publish\API\Repository\Values\Content\ContentInfo |
25
|
|
|
*/ |
26
|
|
|
protected $contentInfo; |
27
|
|
|
|
28
|
|
|
/** @var array */ |
29
|
|
|
protected $path; |
30
|
|
|
|
31
|
|
|
/** @var \eZ\Publish\API\Repository\Values\Content\Location */ |
32
|
|
|
protected $parentLocation; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the content info of the content object of this trash item. |
36
|
|
|
* |
37
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
38
|
|
|
*/ |
39
|
|
|
public function getContentInfo() |
40
|
|
|
{ |
41
|
|
|
return $this->contentInfo; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getParentLocation(): ?Location |
45
|
|
|
{ |
46
|
|
|
return $this->parentLocation; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Function where list of properties are returned. |
51
|
|
|
* |
52
|
|
|
* Override to add dynamic properties |
53
|
|
|
* |
54
|
|
|
* @uses \parent::getProperties() |
55
|
|
|
* |
56
|
|
|
* @param array $dynamicProperties |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
|
|
protected function getProperties($dynamicProperties = ['contentId', 'path']) |
61
|
|
|
{ |
62
|
|
|
return parent::getProperties($dynamicProperties); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Magic getter for retrieving convenience properties. |
67
|
|
|
* |
68
|
|
|
* @param string $property The name of the property to retrieve |
69
|
|
|
* |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
public function __get($property) |
73
|
|
|
{ |
74
|
|
|
switch ($property) { |
75
|
|
|
case 'contentId': |
76
|
|
|
return $this->contentInfo->id; |
77
|
|
|
case 'path': |
78
|
|
|
if ($this->path !== null) { |
79
|
|
|
return $this->path; |
80
|
|
|
} |
81
|
|
|
if (isset($this->pathString[1]) && $this->pathString[0] === '/') { |
82
|
|
|
return $this->path = explode('/', trim($this->pathString, '/')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return $this->path = []; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return parent::__get($property); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Magic isset for signaling existence of convenience properties. |
93
|
|
|
* |
94
|
|
|
* @param string $property |
95
|
|
|
* |
96
|
|
|
* @return bool |
97
|
|
|
*/ |
98
|
|
|
public function __isset($property) |
99
|
|
|
{ |
100
|
|
|
if ($property === 'contentId' || $property === 'path') { |
101
|
|
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return parent::__isset($property); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: