/** * * @param array $actionData * @param array $params * * @return Response */ public function getResponse(array $actionData = array(), array $params = array()) { $actionName = isset($params['actionName']) ? $params['actionName'] : null; unset($params['actionName']); if (null === $actionName) { throw new Exception('Missing ResultType parameter "actionName"'); } $this->context->setActionName($actionName); foreach ($params as $key => $value) { if (!empty($value) && strpos($value, ':', 0) !== false && array_key_exists(substr($value, 1), $actionData)) { $value = $actionData[substr($value, 1)]; } $this->context->getRequest()->query->set($key, $value); } return $this->application->runAction($this->context); }
/** * Runs the Application for a defined (or new) HTTP request * * @param Request $request The HTTP request (optional) * * @return mixed */ public function run(Request $request = null) { $this->notify(new BootEvent($this)); if (null === $request) { $request = Request::createFromGlobals(); } $context = new Context($request); try { $this->notify(new RequestEvent($request, $this, $context)); if (!$context->isReady()) { $this->notify(new DispatchEvent($this, $context)); } if (!$context->isReady()) { if (null === $this->defaultAction || $context->isError()) { throw new Exception('No action found'); } $context->setActionName($this->defaultAction); } $result = $this->runAction($context); if (!$context->isDone()) { if ($result instanceof Response) { $context->setResponse($result); } elseif (is_string($result)) { $context->setResponse(new Response($result)); } } if ($context->getResponse() instanceof Response) { $this->notify(new ResponseEvent($context->getResponse(), $this, $context)); } } catch (\Exception $exp) { $event = new ErrorEvent($exp, $this, $context); $this->notify($event); if (!$event->isStopped()) { throw $exp; } else { return null; } } $endEvent = new EndEvent($this, $context); $this->notify($endEvent); if ($endEvent->isStopped()) { return null; } if ($context->getResponse() instanceof Response) { return $context->getResponse(); } return $context->getResult(); }