1 | <?php |
||
24 | class ClassSchema |
||
25 | { |
||
26 | /** |
||
27 | * Available model types |
||
28 | */ |
||
29 | const MODELTYPE_ENTITY = 1; |
||
30 | const MODELTYPE_VALUEOBJECT = 2; |
||
31 | |||
32 | /** |
||
33 | * Name of the class this schema is referring to |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $className; |
||
38 | |||
39 | /** |
||
40 | * Model type of the class this schema is referring to |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $modelType = self::MODELTYPE_ENTITY; |
||
45 | |||
46 | /** |
||
47 | * Whether a repository exists for the class this schema is referring to |
||
48 | * |
||
49 | * @var bool |
||
50 | */ |
||
51 | protected $aggregateRoot = false; |
||
52 | |||
53 | /** |
||
54 | * The name of the property holding the uuid of an entity, if any. |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $uuidPropertyName; |
||
59 | |||
60 | /** |
||
61 | * Properties of the class which need to be persisted |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $properties = []; |
||
66 | |||
67 | /** |
||
68 | * The properties forming the identity of an object |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $identityProperties = []; |
||
73 | |||
74 | /** |
||
75 | * Constructs this class schema |
||
76 | * |
||
77 | * @param string $className Name of the class this schema is referring to |
||
78 | */ |
||
79 | public function __construct($className) |
||
83 | |||
84 | /** |
||
85 | * Returns the class name this schema is referring to |
||
86 | * |
||
87 | * @return string The class name |
||
88 | */ |
||
89 | public function getClassName() |
||
93 | |||
94 | /** |
||
95 | * Adds (defines) a specific property and its type. |
||
96 | * |
||
97 | * @param string $name Name of the property |
||
98 | * @param string $type Type of the property |
||
99 | * @param bool $lazy Whether the property should be lazy-loaded when reconstituting |
||
100 | * @param string $cascade Strategy to cascade the object graph. |
||
101 | */ |
||
102 | public function addProperty($name, $type, $lazy = false, $cascade = '') |
||
112 | |||
113 | /** |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function hasConstructor(): bool |
||
120 | |||
121 | /** |
||
122 | * Returns the given property defined in this schema. Check with |
||
123 | * hasProperty($propertyName) before! |
||
124 | * |
||
125 | * @param string $propertyName |
||
126 | * @return array |
||
127 | */ |
||
128 | public function getProperty($propertyName) |
||
132 | |||
133 | /** |
||
134 | * Returns all properties defined in this schema |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getProperties() |
||
142 | |||
143 | /** |
||
144 | * Sets the model type of the class this schema is referring to. |
||
145 | * |
||
146 | * @param int $modelType The model type, one of the MODELTYPE_* constants. |
||
147 | * @throws \InvalidArgumentException |
||
148 | */ |
||
149 | public function setModelType($modelType) |
||
156 | |||
157 | /** |
||
158 | * Returns the model type of the class this schema is referring to. |
||
159 | * |
||
160 | * @return int The model type, one of the MODELTYPE_* constants. |
||
161 | */ |
||
162 | public function getModelType() |
||
166 | |||
167 | /** |
||
168 | * Marks the class if it is root of an aggregate and therefore accessible |
||
169 | * through a repository - or not. |
||
170 | * |
||
171 | * @param bool $isRoot TRUE if it is the root of an aggregate |
||
172 | */ |
||
173 | public function setAggregateRoot($isRoot) |
||
177 | |||
178 | /** |
||
179 | * Whether the class is an aggregate root and therefore accessible through |
||
180 | * a repository. |
||
181 | * |
||
182 | * @return bool TRUE if it is managed |
||
183 | */ |
||
184 | public function isAggregateRoot() |
||
188 | |||
189 | /** |
||
190 | * If the class schema has a certain property. |
||
191 | * |
||
192 | * @param string $propertyName Name of the property |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function hasProperty($propertyName) |
||
199 | |||
200 | /** |
||
201 | * Sets the property marked as uuid of an object with @uuid |
||
202 | * |
||
203 | * @param string $propertyName |
||
204 | * @throws \InvalidArgumentException |
||
205 | */ |
||
206 | public function setUuidPropertyName($propertyName) |
||
213 | |||
214 | /** |
||
215 | * Gets the name of the property marked as uuid of an object |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getUuidPropertyName() |
||
223 | |||
224 | /** |
||
225 | * Marks the given property as one of properties forming the identity |
||
226 | * of an object. The property must already be registered in the class |
||
227 | * schema. |
||
228 | * |
||
229 | * @param string $propertyName |
||
230 | * @throws \InvalidArgumentException |
||
231 | */ |
||
232 | public function markAsIdentityProperty($propertyName) |
||
242 | |||
243 | /** |
||
244 | * Gets the properties (names and types) forming the identity of an object. |
||
245 | * |
||
246 | * @return array |
||
247 | * @see markAsIdentityProperty() |
||
248 | */ |
||
249 | public function getIdentityProperties() |
||
253 | } |
||
254 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: