1 | <?php |
||
21 | class Relations |
||
22 | { |
||
23 | /** |
||
24 | * Relation stack, i.e. |
||
25 | * <code> |
||
26 | * [ |
||
27 | * 'Model1:Model2' => ['Model1'=>'foreignKey', 'Model2'=>'primaryKey'], |
||
28 | * 'Pages:Users' => ['Pages'=>'userId', 'Users'=>'id'], |
||
29 | * 'PagesTags:Pages' => ['PagesTags'=>'pageId', 'Pages'=>'id'], |
||
30 | * 'PagesTags:Tags' => ['PagesTags'=>'tagId', 'Tags'=>'id'], |
||
31 | * 'Pages:Tags' => ['PagesTags'], |
||
32 | * ] |
||
33 | * </code> |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected static $relations; |
||
38 | |||
39 | /** |
||
40 | * Class map, i.e. |
||
41 | * <code> |
||
42 | * [ |
||
43 | * 'Pages' => '\Application\Pages\Table', |
||
44 | * 'Users' => '\Application\Users\Table', |
||
45 | * ] |
||
46 | * </code> |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected static $modelClassMap; |
||
51 | |||
52 | /** |
||
53 | * Setup relation between two models |
||
54 | * |
||
55 | * @param string $modelOne |
||
56 | * @param string $keyOne |
||
57 | * @param string $modelTwo |
||
58 | * @param string $keyTwo |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | public static function setRelation($modelOne, $keyOne, $modelTwo, $keyTwo) |
||
67 | |||
68 | /** |
||
69 | * Setup multi relations |
||
70 | * |
||
71 | * @param string $modelOne |
||
72 | * @param string $modelTwo |
||
73 | * @param array $relations |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | public static function setRelations($modelOne, $modelTwo, $relations) |
||
85 | |||
86 | /** |
||
87 | * Get relations |
||
88 | * |
||
89 | * @param string $modelOne |
||
90 | * @param string $modelTwo |
||
91 | * |
||
92 | * @return array|false |
||
93 | */ |
||
94 | public static function getRelations($modelOne, $modelTwo) |
||
102 | |||
103 | /** |
||
104 | * findRelation |
||
105 | * |
||
106 | * @param Row $row |
||
107 | * @param string $relation |
||
108 | * |
||
109 | * @return array |
||
110 | * @throws Exception\RelationNotFoundException |
||
111 | */ |
||
112 | 1 | public static function findRelation($row, $relation) |
|
136 | |||
137 | /** |
||
138 | * Find Relations between two tables |
||
139 | * |
||
140 | * @param string $modelOne Table |
||
141 | * @param string $modelTwo Target table |
||
142 | * @param array $keys Keys from first table |
||
143 | * |
||
144 | * @return array |
||
145 | * @throws Exception\RelationNotFoundException |
||
146 | */ |
||
147 | public static function findRelations($modelOne, $modelTwo, $keys) |
||
210 | |||
211 | /** |
||
212 | * Add information about model's classes |
||
213 | * |
||
214 | * @param string $model |
||
215 | * @param string $className |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | 2 | public static function addClassMap($model, $className) |
|
223 | |||
224 | /** |
||
225 | * Get information about Model classes |
||
226 | * |
||
227 | * @param string $model |
||
228 | * |
||
229 | * @return string |
||
230 | * @throws Exception\RelationNotFoundException |
||
231 | */ |
||
232 | 1 | public static function getModelClass($model) |
|
245 | |||
246 | /** |
||
247 | * Get information about Table classes |
||
248 | * |
||
249 | * @param string $modelName |
||
250 | * @param array $data |
||
251 | * |
||
252 | * @return Row |
||
253 | * @throws Exception\RelationNotFoundException |
||
254 | */ |
||
255 | public static function createRow($modelName, $data) |
||
262 | |||
263 | /** |
||
264 | * Fetch by Divider |
||
265 | * |
||
266 | * @param array $input |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | public static function fetch($input) |
||
290 | } |
||
291 |