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