39
39
*/
40
40
trait ControllerTrait
41
41
{
42
+ /**
43
+ * Returns true if the service id is defined.
44
+ *
45
+ * @param string $id The service id
46
+ *
47
+ * @return bool true if the service id is defined, false otherwise
48
+ *
49
+ * @final since version 3.4
50
+ */
51
+ protected function has ($ id )
52
+ {
53
+ return $ this ->container ->has ($ id );
54
+ }
55
+
56
+ /**
57
+ * Gets a container service by its id.
58
+ *
59
+ * @param string $id The service id
60
+ *
61
+ * @return object The service
62
+ *
63
+ * @final since version 3.4
64
+ */
65
+ protected function get ($ id )
66
+ {
67
+ return $ this ->container ->get ($ id );
68
+ }
69
+
42
70
/**
43
71
* Generates a URL from the given parameters.
44
72
*
@@ -49,6 +77,8 @@ trait ControllerTrait
49
77
* @return string The generated URL
50
78
*
51
79
* @see UrlGeneratorInterface
80
+ *
81
+ * @final since version 3.4
52
82
*/
53
83
protected function generateUrl ($ route , $ parameters = array (), $ referenceType = UrlGeneratorInterface::ABSOLUTE_PATH )
54
84
{
@@ -63,6 +93,8 @@ protected function generateUrl($route, $parameters = array(), $referenceType = U
63
93
* @param array $query An array of query parameters
64
94
*
65
95
* @return Response A Response instance
96
+ *
97
+ * @final since version 3.4
66
98
*/
67
99
protected function forward ($ controller , array $ path = array (), array $ query = array ())
68
100
{
@@ -81,6 +113,8 @@ protected function forward($controller, array $path = array(), array $query = ar
81
113
* @param int $status The status code to use for the Response
82
114
*
83
115
* @return RedirectResponse
116
+ *
117
+ * @final since version 3.4
84
118
*/
85
119
protected function redirect ($ url , $ status = 302 )
86
120
{
@@ -95,6 +129,8 @@ protected function redirect($url, $status = 302)
95
129
* @param int $status The status code to use for the Response
96
130
*
97
131
* @return RedirectResponse
132
+ *
133
+ * @final since version 3.4
98
134
*/
99
135
protected function redirectToRoute ($ route , array $ parameters = array (), $ status = 302 )
100
136
{
@@ -110,6 +146,8 @@ protected function redirectToRoute($route, array $parameters = array(), $status
110
146
* @param array $context Context to pass to serializer when using serializer component
111
147
*
112
148
* @return JsonResponse
149
+ *
150
+ * @final since version 3.4
113
151
*/
114
152
protected function json ($ data , $ status = 200 , $ headers = array (), $ context = array ())
115
153
{
@@ -132,6 +170,8 @@ protected function json($data, $status = 200, $headers = array(), $context = arr
132
170
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline")
133
171
*
134
172
* @return BinaryFileResponse
173
+ *
174
+ * @final since version 3.4
135
175
*/
136
176
protected function file ($ file , $ fileName = null , $ disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT )
137
177
{
@@ -148,6 +188,8 @@ protected function file($file, $fileName = null, $disposition = ResponseHeaderBa
148
188
* @param string $message The message
149
189
*
150
190
* @throws \LogicException
191
+ *
192
+ * @final since version 3.4
151
193
*/
152
194
protected function addFlash ($ type , $ message )
153
195
{
@@ -167,6 +209,8 @@ protected function addFlash($type, $message)
167
209
* @return bool
168
210
*
169
211
* @throws \LogicException
212
+ *
213
+ * @final since version 3.4
170
214
*/
171
215
protected function isGranted ($ attributes , $ subject = null )
172
216
{
@@ -186,6 +230,8 @@ protected function isGranted($attributes, $subject = null)
186
230
* @param string $message The message passed to the exception
187
231
*
188
232
* @throws AccessDeniedException
233
+ *
234
+ * @final since version 3.4
189
235
*/
190
236
protected function denyAccessUnlessGranted ($ attributes , $ subject = null , $ message = 'Access Denied. ' )
191
237
{
@@ -205,6 +251,8 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, $messag
205
251
* @param array $parameters An array of parameters to pass to the view
206
252
*
207
253
* @return string The rendered view
254
+ *
255
+ * @final since version 3.4
208
256
*/
209
257
protected function renderView ($ view , array $ parameters = array ())
210
258
{
@@ -227,6 +275,8 @@ protected function renderView($view, array $parameters = array())
227
275
* @param Response $response A response instance
228
276
*
229
277
* @return Response A Response instance
278
+ *
279
+ * @final since version 3.4
230
280
*/
231
281
protected function render ($ view , array $ parameters = array (), Response $ response = null )
232
282
{
@@ -255,6 +305,8 @@ protected function render($view, array $parameters = array(), Response $response
255
305
* @param StreamedResponse $response A response instance
256
306
*
257
307
* @return StreamedResponse A StreamedResponse instance
308
+ *
309
+ * @final since version 3.4
258
310
*/
259
311
protected function stream ($ view , array $ parameters = array (), StreamedResponse $ response = null )
260
312
{
@@ -294,6 +346,8 @@ protected function stream($view, array $parameters = array(), StreamedResponse $
294
346
* @param \Exception|null $previous The previous exception
295
347
*
296
348
* @return NotFoundHttpException
349
+ *
350
+ * @final since version 3.4
297
351
*/
298
352
protected function createNotFoundException ($ message = 'Not Found ' , \Exception $ previous = null )
299
353
{
@@ -311,6 +365,8 @@ protected function createNotFoundException($message = 'Not Found', \Exception $p
311
365
* @param \Exception|null $previous The previous exception
312
366
*
313
367
* @return AccessDeniedException
368
+ *
369
+ * @final since version 3.4
314
370
*/
315
371
protected function createAccessDeniedException ($ message = 'Access Denied. ' , \Exception $ previous = null )
316
372
{
@@ -325,6 +381,8 @@ protected function createAccessDeniedException($message = 'Access Denied.', \Exc
325
381
* @param array $options Options for the form
326
382
*
327
383
* @return Form
384
+ *
385
+ * @final since version 3.4
328
386
*/
329
387
protected function createForm ($ type , $ data = null , array $ options = array ())
330
388
{
@@ -338,6 +396,8 @@ protected function createForm($type, $data = null, array $options = array())
338
396
* @param array $options Options for the form
339
397
*
340
398
* @return FormBuilder
399
+ *
400
+ * @final since version 3.4
341
401
*/
342
402
protected function createFormBuilder ($ data = null , array $ options = array ())
343
403
{
@@ -350,6 +410,8 @@ protected function createFormBuilder($data = null, array $options = array())
350
410
* @return Registry
351
411
*
352
412
* @throws \LogicException If DoctrineBundle is not available
413
+ *
414
+ * @final since version 3.4
353
415
*/
354
416
protected function getDoctrine ()
355
417
{
@@ -368,6 +430,8 @@ protected function getDoctrine()
368
430
* @throws \LogicException If SecurityBundle is not available
369
431
*
370
432
* @see TokenInterface::getUser()
433
+ *
434
+ * @final since version 3.4
371
435
*/
372
436
protected function getUser ()
373
437
{
@@ -394,6 +458,8 @@ protected function getUser()
394
458
* @param string $token The actual token sent with the request that should be validated
395
459
*
396
460
* @return bool
461
+ *
462
+ * @final since version 3.4
397
463
*/
398
464
protected function isCsrfTokenValid ($ id , $ token )
399
465
{
0 commit comments