protected function handleRaw(Request $request, $type = self::MASTER_REQUEST)
{
// request
$event = new Event($this, 'core.request', array('request_type' => $type, 'request' => $request));
$this->dispatcher->notifyUntil($event);
if ($event->isProcessed()) {
return $this->filterResponse($event->getReturnValue(), $request, 'A "core.request" listener returned a non response object.', $type);
}
// load controller
if (false === $controller = $this->resolver->getController($request)) {
throw new NotFoundHttpException('Unable to find the controller.');
}
$event = new Event($this, 'core.controller', array('request_type' => $type, 'request' => $request));
$this->dispatcher->filter($event, $controller);
$controller = $event->getReturnValue();
// controller must be a callable
if (!is_callable($controller)) {
throw new \LogicException(sprintf('The controller must be a callable (%s).', var_export($controller, true)));
}
// controller arguments
$arguments = $this->resolver->getArguments($request, $controller);
// call controller
$retval = call_user_func_array($controller, $arguments);
// view
$event = new Event($this, 'core.view', array('request_type' => $type, 'request' => $request));
$this->dispatcher->filter($event, $retval);
return $this->filterResponse($event->getReturnValue(), $request, sprintf('The controller must return a response (instead of %s).', is_object($event->getReturnValue()) ? 'an object of class '.get_class($event->getReturnValue()) : is_array($event->getReturnValue()) ? 'an array' : str_replace("\n", '', var_export($event->getReturnValue(), true))), $type);
}