1 | <?php |
||
27 | class EntityDescriptor implements EntityDescriptorInterface |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var string Entity class name |
||
32 | */ |
||
33 | protected $entity; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $tableName; |
||
39 | |||
40 | /** |
||
41 | * @var Inspector |
||
42 | */ |
||
43 | protected $inspector; |
||
44 | |||
45 | /** |
||
46 | * @var FieldsCollection |
||
47 | */ |
||
48 | protected $fields; |
||
49 | |||
50 | /** |
||
51 | * @var FieldDescriptor |
||
52 | */ |
||
53 | protected $primaryKey; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $adapterAlias = '__undefined__'; |
||
59 | |||
60 | /** |
||
61 | * @var RelationsMap |
||
62 | */ |
||
63 | protected $relationsMap; |
||
64 | |||
65 | protected static $knownRelations = [ |
||
66 | 'belongsTo' => BelongsTo::class |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * EntityDescriptor need an entity FQ class name. |
||
71 | * |
||
72 | * @param string $entity |
||
73 | */ |
||
74 | 14 | public function __construct($entity) |
|
82 | |||
83 | /** |
||
84 | * Gets entity table name |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | 10 | public function getTableName() |
|
95 | |||
96 | /** |
||
97 | * Returns entity fields |
||
98 | * |
||
99 | * @return FieldsCollection|FieldDescriptor[] |
||
100 | */ |
||
101 | 12 | public function getFields() |
|
112 | |||
113 | /** |
||
114 | * Returns the primary key field |
||
115 | * |
||
116 | * @return FieldDescriptor|null |
||
117 | */ |
||
118 | 8 | public function getPrimaryKey() |
|
130 | |||
131 | /** |
||
132 | * Adds a relation class to the list of known relation classes |
||
133 | * |
||
134 | * @param string $annotationName The annotation name to map |
||
135 | * @param string $relationClass The FQ relation class name |
||
136 | * |
||
137 | * @throws InvalidArgumentException If the provided class does not implements |
||
138 | * the RelationInterface interface. |
||
139 | */ |
||
140 | 22 | public static function addRelation($annotationName, $relationClass) |
|
149 | |||
150 | /** |
||
151 | * Determines the table name for current entity |
||
152 | * |
||
153 | * If there is an annotation @table present it will be used |
||
154 | * otherwise the name will be parsed by convention using the |
||
155 | * EntityDescriptor::parseTableName() method. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 4 | private function determineTableName() |
|
168 | |||
169 | /** |
||
170 | * Creates the descriptor if provided property has annotation @column |
||
171 | * |
||
172 | * @param $property |
||
173 | * |
||
174 | * @return self|$this|EntityDescriptor |
||
175 | */ |
||
176 | 6 | private function addDescriptor($property) |
|
188 | |||
189 | /** |
||
190 | * Parses the table name from the class name |
||
191 | * |
||
192 | * @param string $className |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | 10 | public static function parseTableName($className) |
|
211 | |||
212 | /** |
||
213 | * Returns the adapter alias name to use with this entity |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | 6 | public function getAdapterAlias() |
|
230 | |||
231 | /** |
||
232 | * Gets entity class name |
||
233 | * |
||
234 | * @return string |
||
235 | */ |
||
236 | 8 | public function className() |
|
240 | |||
241 | /** |
||
242 | * Gets relations map for this entity |
||
243 | * |
||
244 | * @return RelationsMap |
||
245 | */ |
||
246 | 2 | public function getRelationsMap() |
|
250 | |||
251 | 14 | private function createEntityRelationsMap() |
|
259 | |||
260 | 14 | private function checkRelation($property) |
|
277 | } |