17
17
abstract class QueryRelationManagerBase
18
18
{
19
19
/**
20
- * @var QueryWrapperInterface хранит объект билдера запроса
20
+ * @var QueryWrapperInterface объект билдера запроса
21
21
*/
22
22
protected $ query ;
23
23
24
24
/**
25
- * @var JoinConditionCollection
25
+ * @var JoinConditionCollection коллекция отношений в запросе
26
26
*/
27
- protected $ joinConditionManager ;
27
+ protected $ joinConditionCollection ;
28
28
29
29
/**
30
- * @var TableCollection
30
+ * @var TableCollection коллекция таблиц, участвующих в запросе
31
31
*/
32
- protected $ tableManager ;
32
+ protected $ tableCollection ;
33
33
34
34
/**
35
- * @var callable[]
35
+ * @var callable[] массив функций-коллбэков для внесения дополнительных корректив в запров
36
36
*/
37
37
protected $ filters = [];
38
38
39
39
/**
40
- * @var callable[]
40
+ * @var callable[] карта функций-коллбэков по псевдониму таблицы для внесения изменений в готовые данные результата
41
41
*/
42
42
protected $ modifierMap = [];
43
43
@@ -59,8 +59,8 @@ public static function select(string $className, string $tableAlias): self
59
59
* @param string $className имя класса ActiveRecord, сущности которого нужно подключить
60
60
* @param string $joinAs псевдоним для таблицы, связанной с классом
61
61
* @param string $joinTo псевдоним таблицы, к которой будут подключаться сущности класса
62
- * @param array $joinCondition
63
- * @param string $joinType тип присоединения таблицы (inner, left, right, outer )
62
+ * @param array $joinCondition основное условие присоединения
63
+ * @param string $joinType тип присоединения таблицы (" inner", " left", " right" )
64
64
* @param string|null $extraJoinCondition дополнительные условия join-связи
65
65
* @param array $extraJoinParams параметры дополнительных условий join-связи
66
66
* @return $this
@@ -77,10 +77,10 @@ public function withSingle(
77
77
$ this ->getTableFields ($ className ), $ this ->getPrimaryKey ($ className ), $ containerFieldAlias
78
78
);
79
79
80
- $ this ->tableManager ->add ($ table );
80
+ $ this ->tableCollection ->add ($ table );
81
81
82
- $ this ->joinConditionManager ->add (new JoinCondition (
83
- JoinCondition::TYPE_SINGLE , $ table , $ this ->tableManager ->byAlias ($ joinTo ),
82
+ $ this ->joinConditionCollection ->add (new JoinCondition (
83
+ JoinCondition::TYPE_SINGLE , $ table , $ this ->tableCollection ->byAlias ($ joinTo ),
84
84
$ joinCondition , $ joinType , $ extraJoinCondition , $ extraJoinParams
85
85
));
86
86
@@ -93,8 +93,8 @@ public function withSingle(
93
93
* @param string $className имя класса ActiveRecord, сущности которого нужно подключить
94
94
* @param string $joinAs псевдоним для таблицы, связанной с классом
95
95
* @param string $joinTo псевдоним таблицы, к которой будут подключаться сущности класса
96
- * @param array $joinCondition
97
- * @param string $joinType тип присоединения таблицы (inner, left, right, outer )
96
+ * @param array $joinCondition основное условие присоединения
97
+ * @param string $joinType тип присоединения таблицы (" inner", " left", " right" )
98
98
* @param string|null $extraJoinCondition дополнительные условия join-связи
99
99
* @param array $extraJoinParams параметры дополнительных условий join-связи
100
100
* @return $this
@@ -111,10 +111,10 @@ public function withMultiple(
111
111
$ this ->getTableFields ($ className ), $ this ->getPrimaryKey ($ className ), $ containerFieldAlias
112
112
);
113
113
114
- $ this ->tableManager ->add ($ table );
114
+ $ this ->tableCollection ->add ($ table );
115
115
116
- $ this ->joinConditionManager ->add (new JoinCondition (
117
- JoinCondition::TYPE_MULTIPLE , $ table , $ this ->tableManager ->byAlias ($ joinTo ),
116
+ $ this ->joinConditionCollection ->add (new JoinCondition (
117
+ JoinCondition::TYPE_MULTIPLE , $ table , $ this ->tableCollection ->byAlias ($ joinTo ),
118
118
$ joinCondition , $ joinType , $ extraJoinCondition , $ extraJoinParams
119
119
));
120
120
@@ -159,17 +159,17 @@ public function all($db = null): array
159
159
$ rows = $ this ->query ->all ($ db );
160
160
161
161
$ map = [];
162
- $ this ->tableManager ->each (function (Table $ table ) use (&$ map ) {
162
+ $ this ->tableCollection ->each (function (Table $ table ) use (&$ map ) {
163
163
$ map [$ table ->alias ] = [];
164
164
});
165
165
166
166
$ bufMap = [];
167
167
168
168
foreach ($ rows as $ row ) {
169
- $ this ->tableManager ->each (function (Table $ table ) use (&$ map , &$ row , &$ bufMap ) {
169
+ $ this ->tableCollection ->each (function (Table $ table ) use (&$ map , &$ row , &$ bufMap ) {
170
170
try {
171
171
[$ item , $ pkValue , $ alias , $ aliasTo , $ fkValue , $ containerFieldAlias , $ type ]
172
- = $ table ->getDataFromRow ($ row , $ this ->joinConditionManager );
172
+ = $ table ->getDataFromRow ($ row , $ this ->joinConditionCollection );
173
173
174
174
if (!isset ($ map [$ alias ][$ pkValue ])) {
175
175
$ map [$ alias ][$ pkValue ] = &$ item ;
@@ -208,7 +208,7 @@ public function all($db = null): array
208
208
unset($ item );
209
209
}
210
210
211
- return array_values ($ map [$ this ->tableManager ->getMainTable ()->alias ]);
211
+ return array_values ($ map [$ this ->tableCollection ->getMainTable ()->alias ]);
212
212
}
213
213
214
214
/**
@@ -221,20 +221,20 @@ public function prepare(): QueryWrapperInterface
221
221
$ this ->query = $ this ->createQuery ();
222
222
223
223
$ arSelect = [];
224
- $ this ->tableManager ->each (function (Table $ table ) use (&$ arSelect ) {
224
+ $ this ->tableCollection ->each (function (Table $ table ) use (&$ arSelect ) {
225
225
foreach ($ table ->getFieldMap () as $ fieldName => $ fieldNamePrefixed ) {
226
226
$ arSelect [$ fieldNamePrefixed ] = $ fieldName ;
227
227
}
228
228
});
229
229
230
- $ mainTable = $ this ->tableManager ->getMainTable ();
230
+ $ mainTable = $ this ->tableCollection ->getMainTable ();
231
231
232
232
$ this ->query
233
233
->select ($ arSelect )
234
234
->from ([$ mainTable ->alias => $ mainTable ->name ]);
235
235
236
236
237
- $ this ->joinConditionManager ->each (function (JoinCondition $ cond ) {
237
+ $ this ->joinConditionCollection ->each (function (JoinCondition $ cond ) {
238
238
$ this ->query ->join (
239
239
$ cond ->joinType , [$ cond ->table ->alias => $ cond ->table ->name ], $ cond ->stringify (), $ cond ->extraJoinParams
240
240
);
@@ -248,9 +248,13 @@ public function prepare(): QueryWrapperInterface
248
248
return $ this ->query ;
249
249
}
250
250
251
- public function getTableManager (): TableCollection
251
+ /**
252
+ * Возвращает коллекцию объектов таблиц, участвующих в запросе
253
+ * @return TableCollection
254
+ */
255
+ public function getTableCollection (): TableCollection
252
256
{
253
- return $ this ->tableManager ;
257
+ return $ this ->tableCollection ;
254
258
}
255
259
256
260
/**
@@ -301,10 +305,10 @@ abstract protected function createQuery(): QueryWrapperInterface;
301
305
*/
302
306
protected function __construct (string $ className , string $ alias )
303
307
{
304
- $ this ->tableManager = new TableCollection ();
305
- $ this ->joinConditionManager = new JoinConditionCollection ();
308
+ $ this ->tableCollection = new TableCollection ();
309
+ $ this ->joinConditionCollection = new JoinConditionCollection ();
306
310
307
- $ this ->tableManager ->add (new Table (
311
+ $ this ->tableCollection ->add (new Table (
308
312
$ className , $ this ->getTableName ($ className ), $ alias ,
309
313
$ this ->getTableFields ($ className ), $ this ->getPrimaryKey ($ className )
310
314
));
0 commit comments