Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2abe788

Browse files
committed
minor #24407 [FrameworkBundle] Make Controller helpers final (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] Make Controller helpers final | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - I propose to make all ControllerTrait methods final so we can add type hints. I also propose to add ControllerTrait::has/get so that AbstractController also has the methods. This will help move from Controller to AbstractController. Commits ------- bbc52a1 [FrameworkBundle] Make Controller helpers final
2 parents c66ed68 + bbc52a1 commit 2abe788

File tree

2 files changed

+66
-24
lines changed

2 files changed

+66
-24
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,6 @@ abstract class Controller implements ContainerAwareInterface
2626
use ContainerAwareTrait;
2727
use ControllerTrait;
2828

29-
/**
30-
* Returns true if the service id is defined.
31-
*
32-
* @param string $id The service id
33-
*
34-
* @return bool true if the service id is defined, false otherwise
35-
*/
36-
protected function has($id)
37-
{
38-
return $this->container->has($id);
39-
}
40-
41-
/**
42-
* Gets a container service by its id.
43-
*
44-
* @param string $id The service id
45-
*
46-
* @return object The service
47-
*/
48-
protected function get($id)
49-
{
50-
return $this->container->get($id);
51-
}
52-
5329
/**
5430
* Gets a container configuration parameter by its name.
5531
*

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@
3939
*/
4040
trait ControllerTrait
4141
{
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+
4270
/**
4371
* Generates a URL from the given parameters.
4472
*
@@ -49,6 +77,8 @@ trait ControllerTrait
4977
* @return string The generated URL
5078
*
5179
* @see UrlGeneratorInterface
80+
*
81+
* @final since version 3.4
5282
*/
5383
protected function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
5484
{
@@ -63,6 +93,8 @@ protected function generateUrl($route, $parameters = array(), $referenceType = U
6393
* @param array $query An array of query parameters
6494
*
6595
* @return Response A Response instance
96+
*
97+
* @final since version 3.4
6698
*/
6799
protected function forward($controller, array $path = array(), array $query = array())
68100
{
@@ -81,6 +113,8 @@ protected function forward($controller, array $path = array(), array $query = ar
81113
* @param int $status The status code to use for the Response
82114
*
83115
* @return RedirectResponse
116+
*
117+
* @final since version 3.4
84118
*/
85119
protected function redirect($url, $status = 302)
86120
{
@@ -95,6 +129,8 @@ protected function redirect($url, $status = 302)
95129
* @param int $status The status code to use for the Response
96130
*
97131
* @return RedirectResponse
132+
*
133+
* @final since version 3.4
98134
*/
99135
protected function redirectToRoute($route, array $parameters = array(), $status = 302)
100136
{
@@ -110,6 +146,8 @@ protected function redirectToRoute($route, array $parameters = array(), $status
110146
* @param array $context Context to pass to serializer when using serializer component
111147
*
112148
* @return JsonResponse
149+
*
150+
* @final since version 3.4
113151
*/
114152
protected function json($data, $status = 200, $headers = array(), $context = array())
115153
{
@@ -132,6 +170,8 @@ protected function json($data, $status = 200, $headers = array(), $context = arr
132170
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline")
133171
*
134172
* @return BinaryFileResponse
173+
*
174+
* @final since version 3.4
135175
*/
136176
protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
137177
{
@@ -148,6 +188,8 @@ protected function file($file, $fileName = null, $disposition = ResponseHeaderBa
148188
* @param string $message The message
149189
*
150190
* @throws \LogicException
191+
*
192+
* @final since version 3.4
151193
*/
152194
protected function addFlash($type, $message)
153195
{
@@ -167,6 +209,8 @@ protected function addFlash($type, $message)
167209
* @return bool
168210
*
169211
* @throws \LogicException
212+
*
213+
* @final since version 3.4
170214
*/
171215
protected function isGranted($attributes, $subject = null)
172216
{
@@ -186,6 +230,8 @@ protected function isGranted($attributes, $subject = null)
186230
* @param string $message The message passed to the exception
187231
*
188232
* @throws AccessDeniedException
233+
*
234+
* @final since version 3.4
189235
*/
190236
protected function denyAccessUnlessGranted($attributes, $subject = null, $message = 'Access Denied.')
191237
{
@@ -205,6 +251,8 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, $messag
205251
* @param array $parameters An array of parameters to pass to the view
206252
*
207253
* @return string The rendered view
254+
*
255+
* @final since version 3.4
208256
*/
209257
protected function renderView($view, array $parameters = array())
210258
{
@@ -227,6 +275,8 @@ protected function renderView($view, array $parameters = array())
227275
* @param Response $response A response instance
228276
*
229277
* @return Response A Response instance
278+
*
279+
* @final since version 3.4
230280
*/
231281
protected function render($view, array $parameters = array(), Response $response = null)
232282
{
@@ -255,6 +305,8 @@ protected function render($view, array $parameters = array(), Response $response
255305
* @param StreamedResponse $response A response instance
256306
*
257307
* @return StreamedResponse A StreamedResponse instance
308+
*
309+
* @final since version 3.4
258310
*/
259311
protected function stream($view, array $parameters = array(), StreamedResponse $response = null)
260312
{
@@ -294,6 +346,8 @@ protected function stream($view, array $parameters = array(), StreamedResponse $
294346
* @param \Exception|null $previous The previous exception
295347
*
296348
* @return NotFoundHttpException
349+
*
350+
* @final since version 3.4
297351
*/
298352
protected function createNotFoundException($message = 'Not Found', \Exception $previous = null)
299353
{
@@ -311,6 +365,8 @@ protected function createNotFoundException($message = 'Not Found', \Exception $p
311365
* @param \Exception|null $previous The previous exception
312366
*
313367
* @return AccessDeniedException
368+
*
369+
* @final since version 3.4
314370
*/
315371
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
316372
{
@@ -325,6 +381,8 @@ protected function createAccessDeniedException($message = 'Access Denied.', \Exc
325381
* @param array $options Options for the form
326382
*
327383
* @return Form
384+
*
385+
* @final since version 3.4
328386
*/
329387
protected function createForm($type, $data = null, array $options = array())
330388
{
@@ -338,6 +396,8 @@ protected function createForm($type, $data = null, array $options = array())
338396
* @param array $options Options for the form
339397
*
340398
* @return FormBuilder
399+
*
400+
* @final since version 3.4
341401
*/
342402
protected function createFormBuilder($data = null, array $options = array())
343403
{
@@ -350,6 +410,8 @@ protected function createFormBuilder($data = null, array $options = array())
350410
* @return Registry
351411
*
352412
* @throws \LogicException If DoctrineBundle is not available
413+
*
414+
* @final since version 3.4
353415
*/
354416
protected function getDoctrine()
355417
{
@@ -368,6 +430,8 @@ protected function getDoctrine()
368430
* @throws \LogicException If SecurityBundle is not available
369431
*
370432
* @see TokenInterface::getUser()
433+
*
434+
* @final since version 3.4
371435
*/
372436
protected function getUser()
373437
{
@@ -394,6 +458,8 @@ protected function getUser()
394458
* @param string $token The actual token sent with the request that should be validated
395459
*
396460
* @return bool
461+
*
462+
* @final since version 3.4
397463
*/
398464
protected function isCsrfTokenValid($id, $token)
399465
{

0 commit comments

Comments
 (0)