Handles a request to convert it to a response.
Exceptions are not caught.
Request $request A Request instance:
integer $type The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST):
\LogicException If one of the listener does not behave as expected
NotFoundHttpException When controller cannot be found
private function handleRaw(Request $request, $type = self::MASTER_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". Maybe you forgot to add the matching route in your routing configuration?', $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);
}