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 | * Returns the given property defined in this schema. Check with |
||
115 | * hasProperty($propertyName) before! |
||
116 | * |
||
117 | * @param string $propertyName |
||
118 | * @return array |
||
119 | */ |
||
120 | public function getProperty($propertyName) |
||
124 | |||
125 | /** |
||
126 | * Returns all properties defined in this schema |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | public function getProperties() |
||
134 | |||
135 | /** |
||
136 | * Sets the model type of the class this schema is referring to. |
||
137 | * |
||
138 | * @param int $modelType The model type, one of the MODELTYPE_* constants. |
||
139 | * @throws \InvalidArgumentException |
||
140 | */ |
||
141 | public function setModelType($modelType) |
||
148 | |||
149 | /** |
||
150 | * Returns the model type of the class this schema is referring to. |
||
151 | * |
||
152 | * @return int The model type, one of the MODELTYPE_* constants. |
||
153 | */ |
||
154 | public function getModelType() |
||
158 | |||
159 | /** |
||
160 | * Marks the class if it is root of an aggregate and therefore accessible |
||
161 | * through a repository - or not. |
||
162 | * |
||
163 | * @param bool $isRoot TRUE if it is the root of an aggregate |
||
164 | */ |
||
165 | public function setAggregateRoot($isRoot) |
||
169 | |||
170 | /** |
||
171 | * Whether the class is an aggregate root and therefore accessible through |
||
172 | * a repository. |
||
173 | * |
||
174 | * @return bool TRUE if it is managed |
||
175 | */ |
||
176 | public function isAggregateRoot() |
||
180 | |||
181 | /** |
||
182 | * If the class schema has a certain property. |
||
183 | * |
||
184 | * @param string $propertyName Name of the property |
||
185 | * @return bool |
||
186 | */ |
||
187 | public function hasProperty($propertyName) |
||
191 | |||
192 | /** |
||
193 | * Sets the property marked as uuid of an object with @uuid |
||
194 | * |
||
195 | * @param string $propertyName |
||
196 | * @throws \InvalidArgumentException |
||
197 | */ |
||
198 | public function setUuidPropertyName($propertyName) |
||
205 | |||
206 | /** |
||
207 | * Gets the name of the property marked as uuid of an object |
||
208 | * |
||
209 | * @return string |
||
210 | */ |
||
211 | public function getUuidPropertyName() |
||
215 | |||
216 | /** |
||
217 | * Marks the given property as one of properties forming the identity |
||
218 | * of an object. The property must already be registered in the class |
||
219 | * schema. |
||
220 | * |
||
221 | * @param string $propertyName |
||
222 | * @throws \InvalidArgumentException |
||
223 | */ |
||
224 | public function markAsIdentityProperty($propertyName) |
||
234 | |||
235 | /** |
||
236 | * Gets the properties (names and types) forming the identity of an object. |
||
237 | * |
||
238 | * @return array |
||
239 | * @see markAsIdentityProperty() |
||
240 | */ |
||
241 | public function getIdentityProperties() |
||
245 | } |
||
246 |