You are here

private function HttpKernel::handleRaw in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/HttpKernel.php \Symfony\Component\HttpKernel\HttpKernel::handleRaw()

Handles a request to convert it to a response.

Exceptions are not caught.

Parameters

Request $request A Request instance:

int $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST):

Return value

Response A Response instance

Throws

\LogicException If one of the listener does not behave as expected

NotFoundHttpException When controller cannot be found

1 call to HttpKernel::handleRaw()
HttpKernel::handle in vendor/symfony/http-kernel/HttpKernel.php
Handles a Request to convert it to a Response.

File

vendor/symfony/http-kernel/HttpKernel.php, line 114

Class

HttpKernel
HttpKernel notifies events to convert a Request object to a Response one.

Namespace

Symfony\Component\HttpKernel

Code

private function handleRaw(Request $request, $type = self::MASTER_REQUEST) {
  $this->requestStack
    ->push($request);

  // request
  $event = new GetResponseEvent($this, $request, $type);
  $this->dispatcher
    ->dispatch(KernelEvents::REQUEST, $event);
  if ($event
    ->hasResponse()) {
    return $this
      ->filterResponse($event
      ->getResponse(), $request, $type);
  }

  // load controller
  if (false === ($controller = $this->resolver
    ->getController($request))) {
    throw new NotFoundHttpException(sprintf('Unable to find the controller for path "%s". The route is wrongly configured.', $request
      ->getPathInfo()));
  }
  $event = new FilterControllerEvent($this, $controller, $request, $type);
  $this->dispatcher
    ->dispatch(KernelEvents::CONTROLLER, $event);
  $controller = $event
    ->getController();

  // controller arguments
  $arguments = $this->resolver
    ->getArguments($request, $controller);

  // call controller
  $response = call_user_func_array($controller, $arguments);

  // view
  if (!$response instanceof Response) {
    $event = new GetResponseForControllerResultEvent($this, $request, $type, $response);
    $this->dispatcher
      ->dispatch(KernelEvents::VIEW, $event);
    if ($event
      ->hasResponse()) {
      $response = $event
        ->getResponse();
    }
    if (!$response instanceof Response) {
      $msg = sprintf('The controller must return a response (%s given).', $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 \LogicException($msg);
    }
  }
  return $this
    ->filterResponse($response, $request, $type);
}