1 | <?php |
||
25 | class EntityDescriptor implements EntityDescriptorInterface |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * @var string Entity class name |
||
30 | */ |
||
31 | protected $entity; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $tableName; |
||
37 | |||
38 | /** |
||
39 | * @var Inspector |
||
40 | */ |
||
41 | protected $inspector; |
||
42 | |||
43 | /** |
||
44 | * @var FieldsCollection |
||
45 | */ |
||
46 | protected $fields; |
||
47 | |||
48 | /** |
||
49 | * @var FieldDescriptor |
||
50 | */ |
||
51 | protected $primaryKey; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $adapterAlias = '__undefined__'; |
||
57 | |||
58 | /** |
||
59 | * @var RelationsMap |
||
60 | */ |
||
61 | protected $relationsMap; |
||
62 | |||
63 | protected static $knownRelations = [ |
||
64 | 'belongsTo' => BelongsTo::class |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * EntityDescriptor need an entity FQ class name. |
||
69 | * |
||
70 | * @param string $entity |
||
71 | */ |
||
72 | 16 | public function __construct($entity) |
|
80 | |||
81 | /** |
||
82 | * Gets entity table name |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 10 | public function getTableName() |
|
93 | |||
94 | /** |
||
95 | * Returns entity fields |
||
96 | * |
||
97 | * @return FieldsCollection|FieldDescriptor[] |
||
98 | */ |
||
99 | 12 | public function getFields() |
|
110 | |||
111 | /** |
||
112 | * Returns the primary key field |
||
113 | * |
||
114 | * @return FieldDescriptor|null |
||
115 | */ |
||
116 | 8 | public function getPrimaryKey() |
|
128 | |||
129 | /** |
||
130 | * Determines the table name for current entity |
||
131 | * |
||
132 | * If there is an annotation @table present it will be used |
||
133 | * otherwise the name will be parsed by convention using the |
||
134 | * EntityDescriptor::parseTableName() method. |
||
135 | * |
||
136 | * @return string |
||
137 | */ |
||
138 | 4 | private function determineTableName() |
|
147 | |||
148 | /** |
||
149 | * Creates the descriptor if provided property has annotation @column |
||
150 | * |
||
151 | * @param $property |
||
152 | * |
||
153 | * @return self|$this|EntityDescriptor |
||
154 | */ |
||
155 | 6 | private function addDescriptor($property) |
|
167 | |||
168 | /** |
||
169 | * Parses the table name from the class name |
||
170 | * |
||
171 | * @param string $className |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | 10 | public static function parseTableName($className) |
|
190 | |||
191 | /** |
||
192 | * Returns the adapter alias name to use with this entity |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | 6 | public function getAdapterAlias() |
|
209 | |||
210 | /** |
||
211 | * Gets entity class name |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | 6 | public function className() |
|
219 | |||
220 | 12 | private function createEntityRelationsMap() |
|
228 | |||
229 | 12 | private function checkRelation($property) |
|
246 | } |