|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Lug package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Lug\Bundle\ResourceBundle\Routing; |
|
13
|
|
|
|
|
14
|
|
|
use Lug\Component\Resource\Model\ResourceInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author GeLo <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class CachedParameterResolver implements ParameterResolverInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var ParameterResolverInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $parameterResolver; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var mixed[] |
|
28
|
|
|
*/ |
|
29
|
|
|
private $cache = []; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param ParameterResolverInterface $parameterResolver |
|
33
|
|
|
*/ |
|
34
|
29 |
|
public function __construct(ParameterResolverInterface $parameterResolver) |
|
35
|
|
|
{ |
|
36
|
29 |
|
$this->parameterResolver = $parameterResolver; |
|
37
|
29 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function resolveApi() |
|
43
|
|
|
{ |
|
44
|
1 |
|
return !isset($this->cache[$key = 'api']) |
|
45
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveApi() |
|
46
|
1 |
|
: $this->cache[$key]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
2 |
|
public function resolveCriteria($mandatory = false) |
|
53
|
|
|
{ |
|
54
|
2 |
|
if (isset($this->cache[$key = 'criteria'])) { |
|
55
|
2 |
|
$criteria = $this->cache[$key]; |
|
56
|
|
|
|
|
57
|
2 |
|
if (!empty($criteria) || !$mandatory) { |
|
58
|
1 |
|
return $criteria; |
|
59
|
|
|
} |
|
60
|
1 |
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
return $this->cache[$key] = $this->parameterResolver->resolveCriteria($mandatory); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
1 |
|
public function resolveCurrentPage() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return !isset($this->cache[$key = 'current_page']) |
|
71
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveCurrentPage() |
|
72
|
1 |
|
: $this->cache[$key]; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* {@inheritdoc} |
|
77
|
|
|
*/ |
|
78
|
1 |
|
public function resolveForm(ResourceInterface $resource) |
|
79
|
|
|
{ |
|
80
|
1 |
|
return !isset($this->cache[$key = 'form_'.spl_object_hash($resource)]) |
|
81
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveForm($resource) |
|
82
|
1 |
|
: $this->cache[$key]; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
1 |
|
public function resolveGrid(ResourceInterface $resource) |
|
89
|
|
|
{ |
|
90
|
1 |
|
return !isset($this->cache[$key = 'grid_'.spl_object_hash($resource)]) |
|
91
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveGrid($resource) |
|
92
|
1 |
|
: $this->cache[$key]; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritdoc} |
|
97
|
|
|
*/ |
|
98
|
1 |
|
public function resolveHateoas() |
|
99
|
|
|
{ |
|
100
|
1 |
|
return !isset($this->cache[$key = 'hateoas']) |
|
101
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveHateoas() |
|
102
|
1 |
|
: $this->cache[$key]; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* {@inheritdoc} |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function resolveLocationRoute() |
|
109
|
|
|
{ |
|
110
|
1 |
|
return !isset($this->cache[$key = 'location_route']) |
|
111
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveLocationRoute() |
|
112
|
1 |
|
: $this->cache[$key]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* {@inheritdoc} |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function resolveLocationRouteParameters($object) |
|
119
|
|
|
{ |
|
120
|
1 |
|
return !isset($this->cache[$key = 'location_route_parameters_'.spl_object_hash($object)]) |
|
121
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveLocationRouteParameters($object) |
|
122
|
1 |
|
: $this->cache[$key]; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* {@inheritdoc} |
|
127
|
|
|
*/ |
|
128
|
1 |
|
public function resolveMaxPerPage() |
|
129
|
|
|
{ |
|
130
|
1 |
|
return !isset($this->cache[$key = 'max_per_page']) |
|
131
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveMaxPerPage() |
|
132
|
1 |
|
: $this->cache[$key]; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* {@inheritdoc} |
|
137
|
|
|
*/ |
|
138
|
1 |
|
public function resolveRedirectRoute() |
|
139
|
|
|
{ |
|
140
|
1 |
|
return !isset($this->cache[$key = 'redirect_route']) |
|
141
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveRedirectRoute() |
|
142
|
1 |
|
: $this->cache[$key]; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* {@inheritdoc} |
|
147
|
|
|
*/ |
|
148
|
1 |
|
public function resolveRedirectRouteParameters($object = null, $forwardParameters = false) |
|
149
|
|
|
{ |
|
150
|
1 |
|
$key = 'redirect_route_parameters'; |
|
151
|
|
|
|
|
152
|
1 |
|
if ($object !== null) { |
|
153
|
1 |
|
$key .= '_'.spl_object_hash($object); |
|
154
|
1 |
|
} |
|
155
|
|
|
|
|
156
|
1 |
|
if ($forwardParameters) { |
|
157
|
1 |
|
$key .= '_forward'; |
|
158
|
1 |
|
} |
|
159
|
|
|
|
|
160
|
1 |
|
return isset($this->cache[$key]) |
|
161
|
1 |
|
? $this->cache[$key] |
|
162
|
1 |
|
: $this->cache[$key] = $this->parameterResolver->resolveRedirectRouteParameters( |
|
163
|
1 |
|
$object, |
|
164
|
|
|
$forwardParameters |
|
165
|
1 |
|
); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return bool |
|
170
|
|
|
*/ |
|
171
|
1 |
|
public function resolveRedirectRouteParametersForward() |
|
172
|
|
|
{ |
|
173
|
1 |
|
return !isset($this->cache[$key = 'redirect_route_parameters_forward']) |
|
174
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveRedirectRouteParametersForward() |
|
175
|
1 |
|
: $this->cache[$key]; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* {@inheritdoc} |
|
180
|
|
|
*/ |
|
181
|
1 |
|
public function resolveRepositoryMethod($action) |
|
182
|
|
|
{ |
|
183
|
1 |
|
return !isset($this->cache[$key = 'repository_method_'.$action]) |
|
184
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveRepositoryMethod($action) |
|
185
|
1 |
|
: $this->cache[$key]; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* {@inheritdoc} |
|
190
|
|
|
*/ |
|
191
|
1 |
|
public function resolveSerializerGroups() |
|
192
|
|
|
{ |
|
193
|
1 |
|
return !isset($this->cache[$key = 'serializer_groups']) |
|
194
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveSerializerGroups() |
|
195
|
1 |
|
: $this->cache[$key]; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* {@inheritdoc} |
|
200
|
|
|
*/ |
|
201
|
1 |
|
public function resolveSerializerNull() |
|
202
|
|
|
{ |
|
203
|
1 |
|
return !isset($this->cache[$key = 'serializer_null']) |
|
204
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveSerializerNull() |
|
205
|
1 |
|
: $this->cache[$key]; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* {@inheritdoc} |
|
210
|
|
|
*/ |
|
211
|
1 |
|
public function resolveSorting() |
|
212
|
|
|
{ |
|
213
|
1 |
|
return !isset($this->cache[$key = 'sorting']) |
|
214
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveSorting() |
|
215
|
1 |
|
: $this->cache[$key]; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* {@inheritdoc} |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function resolveStatusCode($statusCode) |
|
222
|
|
|
{ |
|
223
|
1 |
|
return !isset($this->cache[$key = 'status_code_'.$statusCode]) |
|
224
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveStatusCode($statusCode) |
|
225
|
1 |
|
: $this->cache[$key]; |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* {@inheritdoc} |
|
230
|
|
|
*/ |
|
231
|
1 |
|
public function resolveTemplate() |
|
232
|
|
|
{ |
|
233
|
1 |
|
return !isset($this->cache[$key = 'template']) |
|
234
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveTemplate() |
|
235
|
1 |
|
: $this->cache[$key]; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* {@inheritdoc} |
|
240
|
|
|
*/ |
|
241
|
1 |
|
public function resolveThemes() |
|
242
|
|
|
{ |
|
243
|
1 |
|
return !isset($this->cache[$key = 'themes']) |
|
244
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveThemes() |
|
245
|
1 |
|
: $this->cache[$key]; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* {@inheritdoc} |
|
250
|
|
|
*/ |
|
251
|
1 |
|
public function resolveTranslationDomain() |
|
252
|
|
|
{ |
|
253
|
1 |
|
return !isset($this->cache[$key = 'translation_domain']) |
|
254
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveTranslationDomain() |
|
255
|
1 |
|
: $this->cache[$key]; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* {@inheritdoc} |
|
260
|
|
|
*/ |
|
261
|
1 |
|
public function resolveValidationGroups() |
|
262
|
|
|
{ |
|
263
|
1 |
|
return !isset($this->cache[$key = 'validation_groups']) |
|
264
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveValidationGroups() |
|
265
|
1 |
|
: $this->cache[$key]; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* {@inheritdoc} |
|
270
|
|
|
*/ |
|
271
|
1 |
|
public function resolveVoter() |
|
272
|
|
|
{ |
|
273
|
1 |
|
return !isset($this->cache[$key = 'voter']) |
|
274
|
1 |
|
? $this->cache[$key] = $this->parameterResolver->resolveVoter() |
|
275
|
1 |
|
: $this->cache[$key]; |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|