1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Artprima\QueryFilterBundle\QueryFilter\Config; |
4
|
|
|
|
5
|
|
|
use Artprima\QueryFilterBundle\Request\Request; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class BaseConfig |
9
|
|
|
* |
10
|
|
|
* @author Denis Voytyuk <[email protected]> |
11
|
|
|
* |
12
|
|
|
* @package Artprima\QueryFilterBundle\QueryFilter\Config |
13
|
|
|
*/ |
14
|
|
|
class BaseConfig implements ConfigInterface |
15
|
|
|
{ |
16
|
|
|
private const DEFAULT_LIMIT = 10; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Request |
20
|
|
|
*/ |
21
|
|
|
protected $request; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var int |
25
|
|
|
*/ |
26
|
|
|
protected $defaultLimit; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
protected $allowedLimits; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $searchBy = [ |
37
|
|
|
'args' => [], |
38
|
|
|
'aliases' => [], |
39
|
|
|
'extra' => [], |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array |
44
|
|
|
*/ |
45
|
|
|
protected $sort = [ |
46
|
|
|
'cols' => [], |
47
|
|
|
'default' => [], |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var callable |
52
|
|
|
*/ |
53
|
|
|
protected $repositoryCallback; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var callable |
57
|
|
|
*/ |
58
|
|
|
protected $totalRowsCallback; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
protected $simple = true; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
*/ |
68
|
|
|
protected $strictColumns = false; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
4 |
|
public function setSearchAllowedCols(array $args): ConfigInterface |
74
|
|
|
{ |
75
|
4 |
|
$this->searchBy['args'] = $args; |
76
|
|
|
|
77
|
4 |
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @inheritdoc |
82
|
|
|
*/ |
83
|
5 |
|
public function getSearchAllowedCols(): array |
84
|
|
|
{ |
85
|
5 |
|
return $this->searchBy['args']; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @inheritdoc |
90
|
|
|
*/ |
91
|
1 |
|
public function setSearchByAliases(array $aliases): ConfigInterface |
92
|
|
|
{ |
93
|
|
|
/** @var Alias $alias */ |
94
|
1 |
|
foreach ($aliases as $alias) { |
95
|
1 |
|
$this->searchBy['aliases'][$alias->getName()] = $alias; |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritdoc |
103
|
|
|
*/ |
104
|
|
|
public function addSearchByAliases(Alias $alias): ConfigInterface |
105
|
|
|
{ |
106
|
|
|
$this->searchBy['aliases'][$alias->getName()] = $alias; |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @inheritdoc |
113
|
|
|
*/ |
114
|
4 |
|
public function getSearchByAliases(): array |
115
|
|
|
{ |
116
|
4 |
|
return $this->searchBy['aliases'] ?? []; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @inheritdoc |
121
|
|
|
*/ |
122
|
|
|
public function setSearchByExtra(array $extra): ConfigInterface |
123
|
|
|
{ |
124
|
|
|
$this->searchBy['extra'] = $extra; |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @inheritdoc |
131
|
|
|
*/ |
132
|
4 |
|
public function getSearchByExtra(): array |
133
|
|
|
{ |
134
|
4 |
|
return $this->searchBy['extra']; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @inheritdoc |
139
|
|
|
*/ |
140
|
4 |
|
public function setSortCols(array $cols, array $default = []): ConfigInterface |
141
|
|
|
{ |
142
|
4 |
|
$this->sort['cols'] = $cols; |
143
|
4 |
|
$this->sort['default'] = $default; |
144
|
|
|
|
145
|
4 |
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @inheritdoc |
150
|
|
|
*/ |
151
|
4 |
|
public function getSortCols(): array |
152
|
|
|
{ |
153
|
4 |
|
return $this->sort['cols']; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @inheritdoc |
158
|
|
|
*/ |
159
|
|
|
public function getSortColsDefault(): array |
160
|
|
|
{ |
161
|
|
|
return $this->sort['default']; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @inheritdoc |
166
|
|
|
*/ |
167
|
3 |
|
public function setRepositoryCallback(callable $callback): ConfigInterface |
168
|
|
|
{ |
169
|
3 |
|
$this->repositoryCallback = $callback; |
170
|
|
|
|
171
|
3 |
|
return $this; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @inheritdoc |
176
|
|
|
*/ |
177
|
3 |
|
public function getRepositoryCallback(): callable |
178
|
|
|
{ |
179
|
3 |
|
return $this->repositoryCallback; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @inheritdoc |
184
|
|
|
*/ |
185
|
3 |
|
public function getAllowedLimits(): array |
186
|
|
|
{ |
187
|
3 |
|
return $this->allowedLimits ?? []; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @inheritdoc |
192
|
|
|
*/ |
193
|
3 |
|
public function setAllowedLimits(array $allowedLimits): ConfigInterface |
194
|
|
|
{ |
195
|
3 |
|
$this->allowedLimits = $allowedLimits; |
196
|
|
|
|
197
|
3 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @inheritdoc |
202
|
|
|
*/ |
203
|
3 |
|
public function setDefaultLimit(int $limit): ConfigInterface |
204
|
|
|
{ |
205
|
3 |
|
$this->defaultLimit = $limit; |
206
|
|
|
|
207
|
3 |
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @inheritdoc |
212
|
|
|
*/ |
213
|
|
|
public function getDefaultLimit(): int |
214
|
|
|
{ |
215
|
|
|
return $this->defaultLimit ?? self::DEFAULT_LIMIT; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return Request |
220
|
|
|
*/ |
221
|
5 |
|
public function getRequest(): Request |
222
|
|
|
{ |
223
|
5 |
|
return $this->request; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @inheritdoc |
228
|
|
|
*/ |
229
|
5 |
|
public function setRequest(Request $request): ConfigInterface |
230
|
|
|
{ |
231
|
5 |
|
$this->request = $request; |
232
|
|
|
|
233
|
5 |
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @inheritdoc |
238
|
|
|
*/ |
239
|
2 |
|
public function setStrictColumns(bool $strict): ConfigInterface |
240
|
|
|
{ |
241
|
2 |
|
$this->strictColumns = $strict; |
242
|
|
|
|
243
|
2 |
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @inheritdoc |
248
|
|
|
*/ |
249
|
5 |
|
public function isStrictColumns(): bool |
250
|
|
|
{ |
251
|
5 |
|
return $this->strictColumns; |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|