DefaultController
extends AbstractController
in package
Provides shortcuts for HTTP-related features in controllers.
Table of Contents
Properties
Methods
- getSubscribedServices() : array<string|int, string>
- Returns an array of service types required by such instances, optionally keyed by the service names used internally.
- home() : Response
- index() : Response
- number() : Response
- setContainer() : ContainerInterface|null
- addFlash() : void
- Adds a flash message to the current session for type.
- addLink() : void
- Adds a Link HTTP header to the current response.
- createAccessDeniedException() : AccessDeniedException
- Returns an AccessDeniedException.
- createForm() : FormInterface
- Creates and returns a Form instance from the type of the form.
- createFormBuilder() : FormBuilderInterface
- Creates and returns a form builder instance.
- createNotFoundException() : NotFoundHttpException
- Returns a NotFoundHttpException.
- denyAccessUnlessGranted() : void
- Throws an exception unless the attribute is granted against the current authentication token and optionally supplied subject.
- file() : BinaryFileResponse
- Returns a BinaryFileResponse object with original or customized file name and disposition header.
- forward() : Response
- Forwards the request to another controller.
- generateUrl() : string
- Generates a URL from the given parameters.
- getParameter() : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
- Gets a container parameter by its name.
- getUser() : UserInterface|null
- Get a user from the Security Token Storage.
- isCsrfTokenValid() : bool
- Checks the validity of a CSRF token.
- isGranted() : bool
- Checks if the attribute is granted against the current authentication token and optionally supplied subject.
- json() : JsonResponse
- Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
- redirect() : RedirectResponse
- Returns a RedirectResponse to the given URL.
- redirectToRoute() : RedirectResponse
- Returns a RedirectResponse to the given route with the given parameters.
- render() : Response
- Renders a view.
- renderForm() : Response
- Renders a view and sets the appropriate status code when a form is listed in parameters.
- renderView() : string
- Returns a rendered view.
- stream() : StreamedResponse
- Streams a view.
Properties
$container
protected
ContainerInterface
$container
Methods
getSubscribedServices()
Returns an array of service types required by such instances, optionally keyed by the service names used internally.
public
static getSubscribedServices() : array<string|int, string>
For mandatory dependencies:
- ['logger' => 'Psr\Log\LoggerInterface'] means the objects use the "logger" name internally to fetch a service which must implement Psr\Log\LoggerInterface.
- ['loggers' => 'Psr\Log\LoggerInterface[]'] means the objects use the "loggers" name internally to fetch an iterable of Psr\Log\LoggerInterface instances.
- ['Psr\Log\LoggerInterface'] is a shortcut for
- ['Psr\Log\LoggerInterface' => 'Psr\Log\LoggerInterface']
otherwise:
- ['logger' => '?Psr\Log\LoggerInterface'] denotes an optional dependency
- ['loggers' => '?Psr\Log\LoggerInterface[]'] denotes an optional iterable dependency
- ['?Psr\Log\LoggerInterface'] is a shortcut for
- ['Psr\Log\LoggerInterface' => '?Psr\Log\LoggerInterface']
Return values
array<string|int, string> —The required service types, optionally keyed by service names
home()
public
home() : Response
Return values
Responseindex()
public
index() : Response
Return values
Responsenumber()
public
number() : Response
Return values
ResponsesetContainer()
public
setContainer(ContainerInterface $container) : ContainerInterface|null
Parameters
- $container : ContainerInterface
Tags
Return values
ContainerInterface|nulladdFlash()
Adds a flash message to the current session for type.
protected
addFlash(string $type, mixed $message) : void
Parameters
- $type : string
- $message : mixed
Tags
addLink()
Adds a Link HTTP header to the current response.
protected
addLink(Request $request, LinkInterface $link) : void
Parameters
- $request : Request
- $link : LinkInterface
Tags
createAccessDeniedException()
Returns an AccessDeniedException.
protected
createAccessDeniedException([string $message = 'Access Denied.' ][, Throwable $previous = null ]) : AccessDeniedException
This will result in a 403 response code. Usage example:
throw $this->createAccessDeniedException('Unable to access this page!');
Parameters
- $message : string = 'Access Denied.'
- $previous : Throwable = null
Tags
Return values
AccessDeniedExceptioncreateForm()
Creates and returns a Form instance from the type of the form.
protected
createForm(string $type[, mixed $data = null ][, array<string|int, mixed> $options = [] ]) : FormInterface
Parameters
- $type : string
- $data : mixed = null
- $options : array<string|int, mixed> = []
Return values
FormInterfacecreateFormBuilder()
Creates and returns a form builder instance.
protected
createFormBuilder([mixed $data = null ][, array<string|int, mixed> $options = [] ]) : FormBuilderInterface
Parameters
- $data : mixed = null
- $options : array<string|int, mixed> = []
Return values
FormBuilderInterfacecreateNotFoundException()
Returns a NotFoundHttpException.
protected
createNotFoundException([string $message = 'Not Found' ][, Throwable $previous = null ]) : NotFoundHttpException
This will result in a 404 response code. Usage example:
throw $this->createNotFoundException('Page not found!');
Parameters
- $message : string = 'Not Found'
- $previous : Throwable = null
Return values
NotFoundHttpExceptiondenyAccessUnlessGranted()
Throws an exception unless the attribute is granted against the current authentication token and optionally supplied subject.
protected
denyAccessUnlessGranted(mixed $attribute[, mixed $subject = null ][, string $message = 'Access Denied.' ]) : void
Parameters
- $attribute : mixed
- $subject : mixed = null
- $message : string = 'Access Denied.'
Tags
file()
Returns a BinaryFileResponse object with original or customized file name and disposition header.
protected
file(SplFileInfo|string $file[, string $fileName = null ][, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT ]) : BinaryFileResponse
Parameters
- $file : SplFileInfo|string
- $fileName : string = null
- $disposition : string = ResponseHeaderBag::DISPOSITION_ATTACHMENT
Return values
BinaryFileResponseforward()
Forwards the request to another controller.
protected
forward(string $controller[, array<string|int, mixed> $path = [] ][, array<string|int, mixed> $query = [] ]) : Response
Parameters
- $controller : string
-
The controller name (a string like Bundle\BlogBundle\Controller\PostController::indexAction)
- $path : array<string|int, mixed> = []
- $query : array<string|int, mixed> = []
Return values
ResponsegenerateUrl()
Generates a URL from the given parameters.
protected
generateUrl(string $route[, array<string|int, mixed> $parameters = [] ][, int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH ]) : string
Parameters
- $route : string
- $parameters : array<string|int, mixed> = []
- $referenceType : int = UrlGeneratorInterface::ABSOLUTE_PATH
Tags
Return values
stringgetParameter()
Gets a container parameter by its name.
protected
getParameter(string $name) : array<string|int, mixed>|bool|string|int|float|UnitEnum|null
Parameters
- $name : string
Return values
array<string|int, mixed>|bool|string|int|float|UnitEnum|nullgetUser()
Get a user from the Security Token Storage.
protected
getUser() : UserInterface|null
Tags
Return values
UserInterface|nullisCsrfTokenValid()
Checks the validity of a CSRF token.
protected
isCsrfTokenValid(string $id, string|null $token) : bool
Parameters
- $id : string
-
The id used when generating the token
- $token : string|null
-
The actual token sent with the request that should be validated
Return values
boolisGranted()
Checks if the attribute is granted against the current authentication token and optionally supplied subject.
protected
isGranted(mixed $attribute[, mixed $subject = null ]) : bool
Parameters
- $attribute : mixed
- $subject : mixed = null
Tags
Return values
booljson()
Returns a JsonResponse that uses the serializer component if enabled, or json_encode.
protected
json(mixed $data[, int $status = 200 ][, array<string|int, mixed> $headers = [] ][, array<string|int, mixed> $context = [] ]) : JsonResponse
Parameters
- $data : mixed
- $status : int = 200
- $headers : array<string|int, mixed> = []
- $context : array<string|int, mixed> = []
Return values
JsonResponseredirect()
Returns a RedirectResponse to the given URL.
protected
redirect(string $url[, int $status = 302 ]) : RedirectResponse
Parameters
- $url : string
- $status : int = 302
Return values
RedirectResponseredirectToRoute()
Returns a RedirectResponse to the given route with the given parameters.
protected
redirectToRoute(string $route[, array<string|int, mixed> $parameters = [] ][, int $status = 302 ]) : RedirectResponse
Parameters
- $route : string
- $parameters : array<string|int, mixed> = []
- $status : int = 302
Return values
RedirectResponserender()
Renders a view.
protected
render(string $view[, array<string|int, mixed> $parameters = [] ][, Response $response = null ]) : Response
Parameters
- $view : string
- $parameters : array<string|int, mixed> = []
- $response : Response = null
Return values
ResponserenderForm()
Renders a view and sets the appropriate status code when a form is listed in parameters.
protected
renderForm(string $view[, array<string|int, mixed> $parameters = [] ][, Response $response = null ]) : Response
If an invalid form is found in the list of parameters, a 422 status code is returned.
Parameters
- $view : string
- $parameters : array<string|int, mixed> = []
- $response : Response = null
Return values
ResponserenderView()
Returns a rendered view.
protected
renderView(string $view[, array<string|int, mixed> $parameters = [] ]) : string
Parameters
- $view : string
- $parameters : array<string|int, mixed> = []
Return values
stringstream()
Streams a view.
protected
stream(string $view[, array<string|int, mixed> $parameters = [] ][, StreamedResponse $response = null ]) : StreamedResponse
Parameters
- $view : string
- $parameters : array<string|int, mixed> = []
- $response : StreamedResponse = null