AbstractController
abstract class AbstractController implements ServiceSubscriberInterface
Provides common features needed in controllers.
Traits
Properties
protected ContainerInterface | $container |
Methods
Generates a URL from the given parameters.
Forwards the request to another controller.
Returns a RedirectResponse to the given URL.
Returns a RedirectResponse to the given route with the given parameters.
Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
Returns a BinaryFileResponse object with original or customized file name and disposition header.
Adds a flash message to the current session for type.
Checks if the attributes are granted against the current authentication token and optionally supplied subject.
Throws an exception unless the attributes are granted against the current authentication token and optionally supplied subject.
Returns a rendered view.
Streams a view.
Returns a NotFoundHttpException.
Returns an AccessDeniedException.
Creates and returns a Form instance from the type of the form.
Creates and returns a form builder instance.
Shortcut to return the Doctrine Registry service.
Checks the validity of a CSRF token.
No description
Gets a container parameter by its name.
Returns an array of service types required by such instances, optionally keyed by the service names used internally.
Details
protected string
generateUrl(string $route, array $parameters = array(), int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH)
Generates a URL from the given parameters.
protected Response
forward(string $controller, array $path = array(), array $query = array())
Forwards the request to another controller.
protected RedirectResponse
redirect(string $url, int $status = 302)
Returns a RedirectResponse to the given URL.
protected RedirectResponse
redirectToRoute(string $route, array $parameters = array(), int $status = 302)
Returns a RedirectResponse to the given route with the given parameters.
protected JsonResponse
json($data, int $status = 200, array $headers = array(), array $context = array())
Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
protected BinaryFileResponse
file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT)
Returns a BinaryFileResponse object with original or customized file name and disposition header.
protected
addFlash(string $type, string $message)
Adds a flash message to the current session for type.
protected bool
isGranted($attributes, $subject = null)
Checks if the attributes are granted against the current authentication token and optionally supplied subject.
protected
denyAccessUnlessGranted($attributes, $subject = null, string $message = 'Access Denied.')
Throws an exception unless the attributes are granted against the current authentication token and optionally supplied subject.
protected Response
render(string $view, array $parameters = array(), Response $response = null)
Renders a view.
protected StreamedResponse
stream(string $view, array $parameters = array(), StreamedResponse $response = null)
Streams a view.
protected NotFoundHttpException
createNotFoundException(string $message = 'Not Found', Exception $previous = null)
Returns a NotFoundHttpException.
This will result in a 404 response code. Usage example:
throw $this->createNotFoundException('Page not found!');
protected AccessDeniedException
createAccessDeniedException(string $message = 'Access Denied.', Exception $previous = null)
Returns an AccessDeniedException.
This will result in a 403 response code. Usage example:
throw $this->createAccessDeniedException('Unable to access this page!');
protected FormInterface
createForm(string $type, $data = null, array $options = array())
Creates and returns a Form instance from the type of the form.
protected FormBuilderInterface
createFormBuilder($data = null, array $options = array())
Creates and returns a form builder instance.
protected bool
isCsrfTokenValid(string $id, string|null $token)
Checks the validity of a CSRF token.
static array
getSubscribedServices()
Returns an array of service types required by such instances, optionally keyed by the service names used internally.
For mandatory dependencies:
- array('logger' => 'Psr\Log\LoggerInterface') means the objects use the "logger" name internally to fetch a service which must implement Psr\Log\LoggerInterface.
- array('loggers' => 'Psr\Log\LoggerInterface[]') means the objects use the "loggers" name internally to fetch an iterable of Psr\Log\LoggerInterface instances.
- array('Psr\Log\LoggerInterface') is a shortcut for
- array('Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface')
otherwise:
- array('logger' => '?Psr\Log\LoggerInterface') denotes an optional dependency
- array('loggers' => '?Psr\Log\LoggerInterface[]') denotes an optional iterable dependency
- array('?Psr\Log\LoggerInterface') is a shortcut for
- array('Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface')