1 | <?php |
||
18 | class EntityMetadata implements AttributeInterface, RelationshipInterface, MergeableInterface |
||
19 | { |
||
20 | /** |
||
21 | * Uses properties (attributes and relationships) |
||
22 | */ |
||
23 | use Traits\PropertiesTrait; |
||
24 | |||
25 | /** |
||
26 | * The id key name and type. |
||
27 | */ |
||
28 | const ID_KEY = 'id'; |
||
29 | const ID_TYPE = 'string'; |
||
30 | |||
31 | /** |
||
32 | * Whether this class is abstract. |
||
33 | * |
||
34 | * @var bool |
||
35 | */ |
||
36 | public $abstract = false; |
||
37 | |||
38 | /** |
||
39 | * An array of attribute default values for this model. |
||
40 | * Keyed by field name. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | public $defaultValues = []; |
||
45 | |||
46 | /** |
||
47 | * The entity type this entity extends. |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | public $extends; |
||
52 | |||
53 | /** |
||
54 | * All mixins assigned to this entity. |
||
55 | * |
||
56 | * @var MixinMetadata[] |
||
57 | */ |
||
58 | public $mixins = []; |
||
59 | |||
60 | /** |
||
61 | * Child entity types this entity owns. |
||
62 | * Only used for polymorphic entities. |
||
63 | * |
||
64 | * @var array |
||
65 | */ |
||
66 | public $ownedTypes = []; |
||
67 | |||
68 | /** |
||
69 | * The persistence metadata for this entity. |
||
70 | * |
||
71 | * @var StorageLayerInterface |
||
72 | */ |
||
73 | public $persistence; |
||
74 | |||
75 | /** |
||
76 | * Whether this class is considered polymorphic. |
||
77 | * |
||
78 | * @var bool |
||
79 | */ |
||
80 | public $polymorphic = false; |
||
81 | |||
82 | /** |
||
83 | * The search metadata for this entity. |
||
84 | * |
||
85 | * @var StorageLayerInterface |
||
86 | */ |
||
87 | public $search; |
||
88 | |||
89 | /** |
||
90 | * Uniquely defines the type of entity. |
||
91 | * |
||
92 | * @var string |
||
93 | */ |
||
94 | public $type; |
||
95 | |||
96 | /** |
||
97 | * Constructor. |
||
98 | * |
||
99 | * @param string $type The resource identifier type. |
||
100 | */ |
||
101 | public function __construct($type) |
||
105 | |||
106 | /** |
||
107 | * Adds a mixin (and its attributes and relationships) to this entity. |
||
108 | * |
||
109 | * @param MixinMetadata $mixin |
||
110 | * @return self |
||
111 | */ |
||
112 | public function addMixin(MixinMetadata $mixin) |
||
132 | |||
133 | /** |
||
134 | * Determines if a mixin exists. |
||
135 | * |
||
136 | * @param string $mixinName |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function hasMixin($mixinName) |
||
143 | |||
144 | /** |
||
145 | * Gets the parent entity type. |
||
146 | * For entities that are extended. |
||
147 | * |
||
148 | * @return string|null |
||
149 | */ |
||
150 | public function getParentEntityType() |
||
154 | |||
155 | /** |
||
156 | * Whether this metadata represents an abstract class. |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | public function isAbstract() |
||
164 | |||
165 | /** |
||
166 | * Whether this metadata represents a polymorphic class. |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function isPolymorphic() |
||
174 | |||
175 | /** |
||
176 | * Deteremines whether search is enabled for this model. |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function isSearchEnabled() |
||
184 | |||
185 | /** |
||
186 | * Determines if this is a child entity of another entity. |
||
187 | * |
||
188 | * @return bool |
||
189 | */ |
||
190 | public function isChildEntity() |
||
194 | |||
195 | /** |
||
196 | * {@inheritDoc} |
||
197 | */ |
||
198 | public function merge(MergeableInterface $metadata) |
||
216 | |||
217 | /** |
||
218 | * Sets this metadata as representing an abstract class. |
||
219 | * |
||
220 | * @param bool $bit |
||
221 | * @return self |
||
222 | */ |
||
223 | public function setAbstract($bit = true) |
||
228 | |||
229 | /** |
||
230 | * Sets the persistence metadata for this entity. |
||
231 | * |
||
232 | * @param StorageLayerInterface $persistence |
||
233 | * @return self |
||
234 | */ |
||
235 | public function setPersistence(StorageLayerInterface $persistence) |
||
240 | |||
241 | /** |
||
242 | * Sets this metadata as representing a polymorphic class. |
||
243 | * |
||
244 | * @param bool $bit |
||
245 | * @return self |
||
246 | */ |
||
247 | public function setPolymorphic($bit = true) |
||
252 | |||
253 | /** |
||
254 | * Sets the search metadata for this entity. |
||
255 | * |
||
256 | * @param StorageLayerInterface $search |
||
257 | * @return self |
||
258 | */ |
||
259 | public function setSearch(StorageLayerInterface $search) |
||
264 | |||
265 | /** |
||
266 | * Sets the entity type. |
||
267 | * |
||
268 | * @param string $type |
||
269 | * @return self |
||
270 | * @throws MetadataException If the type is not a string or is empty. |
||
271 | */ |
||
272 | public function setType($type) |
||
280 | |||
281 | /** |
||
282 | * Merges attributes with this instance's attributes. |
||
283 | * |
||
284 | * @param array $toAdd |
||
285 | * @return self |
||
286 | */ |
||
287 | private function mergeAttributes(array $toAdd) |
||
294 | |||
295 | /** |
||
296 | * Merges mixins with this instance's mixins. |
||
297 | * |
||
298 | * @param array $toAdd |
||
299 | * @return self |
||
300 | */ |
||
301 | private function mergeMixins(array $toAdd) |
||
310 | |||
311 | /** |
||
312 | * Merges relationships with this instance's relationships. |
||
313 | * |
||
314 | * @param array $toAdd |
||
315 | * @return self |
||
316 | */ |
||
317 | private function mergeRelationships(array $toAdd) |
||
324 | } |
||
325 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: