forked from ezsystems/ezpublish-kernel
/
User.php
169 lines (149 loc) · 4.79 KB
/
User.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/**
* File containing the eZ\Publish\Core\Repository\Values\User\User class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace eZ\Publish\Core\Repository\Values\User;
use eZ\Publish\API\Repository\Values\User\User as APIUser;
/**
* This class represents a user value.
*
* @internal Meant for internal use by Repository, type hint against API object instead.
*/
class User extends APIUser
{
/**
* Internal content representation.
*
* @var \eZ\Publish\API\Repository\Values\Content\Content
*/
protected $content;
/**
* Returns the VersionInfo for this version.
*
* @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
*/
public function getVersionInfo()
{
return $this->content->getVersionInfo();
}
/**
* Returns a field value for the given value
* $version->fields[$fieldDefId][$languageCode] is an equivalent call
* if no language is given on a translatable field this method returns
* the value of the initial language of the version if present, otherwise null.
* On non translatable fields this method ignores the languageCode parameter.
*
* @param string $fieldDefIdentifier
* @param string $languageCode
*
* @return mixed a primitive type or a field type Value object depending on the field type.
*/
public function getFieldValue($fieldDefIdentifier, $languageCode = null)
{
return $this->content->getFieldValue($fieldDefIdentifier, $languageCode);
}
/**
* This method returns the complete fields collection.
*
* @return \eZ\Publish\API\Repository\Values\Content\Field[]
*/
public function getFields()
{
return $this->content->getFields();
}
/**
* This method returns the fields for a given language and non translatable fields.
*
* If note set the initialLanguage of the content version is used.
*
* @param string $languageCode
*
* @return \eZ\Publish\API\Repository\Values\Content\Field[] with field identifier as keys
*/
public function getFieldsByLanguage($languageCode = null)
{
return $this->content->getFieldsByLanguage($languageCode);
}
/**
* This method returns the field for a given field definition identifier and language.
*
* If not set the initialLanguage of the content version is used.
*
* @param string $fieldDefIdentifier
* @param string|null $languageCode
*
* @return \eZ\Publish\API\Repository\Values\Content\Field|null A {@link Field} or null if nothing is found
*/
public function getField($fieldDefIdentifier, $languageCode = null)
{
return $this->content->getField($fieldDefIdentifier, $languageCode);
}
/**
* Function where list of properties are returned.
*
* Override to add dynamic properties
*
* @uses \parent::getProperties()
*
* @param array $dynamicProperties
*
* @return array
*/
protected function getProperties($dynamicProperties = ['id', 'contentInfo', 'versionInfo', 'fields'])
{
return parent::getProperties($dynamicProperties);
}
/**
* Magic getter for retrieving convenience properties.
*
* @param string $property The name of the property to retrieve
*
* @return mixed
*/
public function __get($property)
{
switch ($property) {
case 'contentInfo':
return $this->getVersionInfo()->getContentInfo();
case 'id':
return $this->getVersionInfo()->getContentInfo()->id;
case 'versionInfo':
return $this->getVersionInfo();
case 'fields':
return $this->getFields();
case 'content':
// trigger error for this, but for BC let it pass on to normal __get lookup for now
@trigger_error(
sprintf('%s is and internal property, usage is deprecated as of 6.10. User itself exposes everything needed.', $property),
E_USER_DEPRECATED
);
}
return parent::__get($property);
}
/**
* Magic isset for signaling existence of convenience properties.
*
* @param string $property
*
* @return bool
*/
public function __isset($property)
{
if ($property === 'contentInfo') {
return true;
}
if ($property === 'id') {
return true;
}
if ($property === 'versionInfo') {
return true;
}
if ($property === 'fields') {
return true;
}
return parent::__isset($property);
}
}