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

Skip to content

[FrameworkBundle] Make Controller helpers final #24407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,6 @@ abstract class Controller implements ContainerAwareInterface
use ContainerAwareTrait;
use ControllerTrait;

/**
* Returns true if the service id is defined.
*
* @param string $id The service id
*
* @return bool true if the service id is defined, false otherwise
*/
protected function has($id)
{
return $this->container->has($id);
}

/**
* Gets a container service by its id.
*
* @param string $id The service id
*
* @return object The service
*/
protected function get($id)
{
return $this->container->get($id);
}

/**
* Gets a container configuration parameter by its name.
*
Expand Down
66 changes: 66 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@
*/
trait ControllerTrait
{
/**
* Returns true if the service id is defined.
*
* @param string $id The service id
*
* @return bool true if the service id is defined, false otherwise
*
* @final since version 3.4
*/
protected function has($id)
{
return $this->container->has($id);
}

/**
* Gets a container service by its id.
*
* @param string $id The service id
*
* @return object The service
*
* @final since version 3.4
*/
protected function get($id)
{
return $this->container->get($id);
}

/**
* Generates a URL from the given parameters.
*
Expand All @@ -49,6 +77,8 @@ trait ControllerTrait
* @return string The generated URL
*
* @see UrlGeneratorInterface
*
* @final since version 3.4
*/
protected function generateUrl($route, $parameters = array(), $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
{
Expand All @@ -63,6 +93,8 @@ protected function generateUrl($route, $parameters = array(), $referenceType = U
* @param array $query An array of query parameters
*
* @return Response A Response instance
*
* @final since version 3.4
*/
protected function forward($controller, array $path = array(), array $query = array())
{
Expand All @@ -81,6 +113,8 @@ protected function forward($controller, array $path = array(), array $query = ar
* @param int $status The status code to use for the Response
*
* @return RedirectResponse
*
* @final since version 3.4
*/
protected function redirect($url, $status = 302)
{
Expand All @@ -95,6 +129,8 @@ protected function redirect($url, $status = 302)
* @param int $status The status code to use for the Response
*
* @return RedirectResponse
*
* @final since version 3.4
*/
protected function redirectToRoute($route, array $parameters = array(), $status = 302)
{
Expand All @@ -110,6 +146,8 @@ protected function redirectToRoute($route, array $parameters = array(), $status
* @param array $context Context to pass to serializer when using serializer component
*
* @return JsonResponse
*
* @final since version 3.4
*/
protected function json($data, $status = 200, $headers = array(), $context = array())
{
Expand All @@ -132,6 +170,8 @@ protected function json($data, $status = 200, $headers = array(), $context = arr
* @param string $disposition Disposition of response ("attachment" is default, other type is "inline")
*
* @return BinaryFileResponse
*
* @final since version 3.4
*/
protected function file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
{
Expand All @@ -148,6 +188,8 @@ protected function file($file, $fileName = null, $disposition = ResponseHeaderBa
* @param string $message The message
*
* @throws \LogicException
*
* @final since version 3.4
*/
protected function addFlash($type, $message)
{
Expand All @@ -167,6 +209,8 @@ protected function addFlash($type, $message)
* @return bool
*
* @throws \LogicException
*
* @final since version 3.4
*/
protected function isGranted($attributes, $subject = null)
{
Expand All @@ -186,6 +230,8 @@ protected function isGranted($attributes, $subject = null)
* @param string $message The message passed to the exception
*
* @throws AccessDeniedException
*
* @final since version 3.4
*/
protected function denyAccessUnlessGranted($attributes, $subject = null, $message = 'Access Denied.')
{
Expand All @@ -205,6 +251,8 @@ protected function denyAccessUnlessGranted($attributes, $subject = null, $messag
* @param array $parameters An array of parameters to pass to the view
*
* @return string The rendered view
*
* @final since version 3.4
*/
protected function renderView($view, array $parameters = array())
{
Expand All @@ -227,6 +275,8 @@ protected function renderView($view, array $parameters = array())
* @param Response $response A response instance
*
* @return Response A Response instance
*
* @final since version 3.4
*/
protected function render($view, array $parameters = array(), Response $response = null)
{
Expand Down Expand Up @@ -255,6 +305,8 @@ protected function render($view, array $parameters = array(), Response $response
* @param StreamedResponse $response A response instance
*
* @return StreamedResponse A StreamedResponse instance
*
* @final since version 3.4
*/
protected function stream($view, array $parameters = array(), StreamedResponse $response = null)
{
Expand Down Expand Up @@ -294,6 +346,8 @@ protected function stream($view, array $parameters = array(), StreamedResponse $
* @param \Exception|null $previous The previous exception
*
* @return NotFoundHttpException
*
* @final since version 3.4
*/
protected function createNotFoundException($message = 'Not Found', \Exception $previous = null)
{
Expand All @@ -311,6 +365,8 @@ protected function createNotFoundException($message = 'Not Found', \Exception $p
* @param \Exception|null $previous The previous exception
*
* @return AccessDeniedException
*
* @final since version 3.4
*/
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
{
Expand All @@ -325,6 +381,8 @@ protected function createAccessDeniedException($message = 'Access Denied.', \Exc
* @param array $options Options for the form
*
* @return Form
*
* @final since version 3.4
*/
protected function createForm($type, $data = null, array $options = array())
{
Expand All @@ -338,6 +396,8 @@ protected function createForm($type, $data = null, array $options = array())
* @param array $options Options for the form
*
* @return FormBuilder
*
* @final since version 3.4
*/
protected function createFormBuilder($data = null, array $options = array())
{
Expand All @@ -350,6 +410,8 @@ protected function createFormBuilder($data = null, array $options = array())
* @return Registry
*
* @throws \LogicException If DoctrineBundle is not available
*
* @final since version 3.4
*/
protected function getDoctrine()
{
Expand All @@ -368,6 +430,8 @@ protected function getDoctrine()
* @throws \LogicException If SecurityBundle is not available
*
* @see TokenInterface::getUser()
*
* @final since version 3.4
*/
protected function getUser()
{
Expand All @@ -394,6 +458,8 @@ protected function getUser()
* @param string $token The actual token sent with the request that should be validated
*
* @return bool
*
* @final since version 3.4
*/
protected function isCsrfTokenValid($id, $token)
{
Expand Down