Symfony\Component\HttpKernel\Event\GetResponseEvent::setResponse PHP Method

setResponse() public method

Sets a response and stops event propagation
public setResponse ( Response $response )
$response Symfony\Component\HttpFoundation\Response
    public function setResponse(Response $response)
    {
        $this->response = $response;

        $this->stopPropagation();
    }

Usage Example

 /**
  * Determine whether the page is configured to be offline.
  *
  * @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
  *   The event to process.
  */
 public function onKernelRequestMaintenance(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     $route_match = RouteMatch::createFromRequest($request);
     $path = $request->attributes->get('_system_path');
     if ($this->maintenanceMode->applies($route_match)) {
         // If the site is offline, log out unprivileged users.
         if ($this->account->isAuthenticated() && !$this->maintenanceMode->exempt($this->account)) {
             user_logout();
             // Redirect to homepage.
             $event->setResponse(new RedirectResponse($this->url('<front>', [], ['absolute' => TRUE])));
             return;
         }
     }
     if ($this->account->isAuthenticated()) {
         if ($path == 'user/login') {
             // If the user is already logged in, redirect to their profile page.
             $event->setResponse($this->redirect('entity.user.canonical', ['user' => $this->account->id()]));
             return;
         }
         if ($path == 'user/register') {
             // If the user is already registered, redirect to their edit page.
             $event->setResponse(new RedirectResponse($this->url('entity.user.edit_form', ['user' => $this->account->id()], ['absolute' => TRUE])));
             return;
         }
     }
 }
All Usage Examples Of Symfony\Component\HttpKernel\Event\GetResponseEvent::setResponse