is a PHP function you create that reads information from the Request object and creates and returns a Response object. https://symfony.com/doc/current/controller.html
component provides a structured process for converting a Request into a Response by making use of the EventDispatcher component. The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatcher component. The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatcher component. https://symfony.com/doc/current/components/http_kernel.html
class MaintenanceModeListener { public function __construct( private readonly bool $enabled, private readonly Environment $twig, ) { } public function __invoke(RequestEvent $event) { if ($this->enabled) { $event->setResponse(new Response($this->twig->render('maintenance.html.twig'))); } } }
class MaintenanceModeListener { public function __construct( private readonly bool $enabled, private readonly Environment $twig, ) { } public function __invoke(RequestEvent $event) { if ($this->enabled) { $event->setResponse(new Response($this->twig->render('maintenance.html.twig'))); } } }
class MaintenanceModeListener { public function __construct( private readonly bool $enabled, private readonly Environment $twig, ) { } public function __invoke(RequestEvent $event) { if ($this->enabled) { $event->setResponse(new Response($this->twig->render('maintenance.html.twig'))); } } }
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; interface ValueResolverInterface { public function resolve(Request $request, ArgumentMetadata $argument): iterable; }
$event->getController(); $arguments = $event->getArguments(); // call controller $response = $controller(...$arguments); // view if (!$response instanceof Response) { $event = new ViewEvent($this, $request, $type, $response, $event); $this->dispatcher->dispatch($event, KernelEvents::VIEW); if ($event->hasResponse()) { $response = $event->getResponse(); } else { $msg = sprintf('The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned %s.', $this- >varToString($response)); // the user may have forgotten to return something if (null === $response) { $msg .= ' Did you forget to add a return statement somewhere in your controller?'; } throw new ControllerDoesNotReturnResponseException($msg, $controller, __FILE__, __LINE__ - 17); } } Anatomie des Request Handling - SymfonyLive Berlin 2023
$event->getController(); $arguments = $event->getArguments(); // call controller $response = $controller(...$arguments); // view if (!$response instanceof Response) { $event = new ViewEvent($this, $request, $type, $response, $event); $this->dispatcher->dispatch($event, KernelEvents::VIEW); if ($event->hasResponse()) { $response = $event->getResponse(); } else { $msg = sprintf('The controller must return a "Symfony\Component\HttpFoundation\Response" object but it returned %s.', $this- >varToString($response)); // the user may have forgotten to return something if (null === $response) { $msg .= ' Did you forget to add a return statement somewhere in your controller?'; } throw new ControllerDoesNotReturnResponseException($msg, $controller, __FILE__, __LINE__ - 17); } } Anatomie des Request Handling - SymfonyLive Berlin 2023
handleThrowable(\Throwable $e, Request $request, int $type): Response { $event = new ExceptionEvent($this, $request, $type, $e); $this->dispatcher->dispatch($event, KernelEvents::EXCEPTION); // a listener might have replaced the exception $e = $event->getThrowable(); if (!$event->hasResponse()) { $this->finishRequest($request, $type); throw $e; } $response = $event->getResponse(); // the developer asked for a specific status code if (!$event->isAllowingCustomResponseCode() && !$response->isClientError() && !$response- >isServerError() && !$response->isRedirect()) { // ensure that we actually have an error response if ($e instanceof HttpExceptionInterface) { Anatomie des Request Handling - SymfonyLive Berlin 2023
class UnprocessableEntityListener { public function __invoke(ExceptionEvent $event): void { if ($event->getThrowable() instanceof DiscountExpiredException) { $event->setResponse(new Response('', Response::HTTP_UNPROCESSABLE_ENTITY)); } } }