Beispiel #1
0
 /**
  * Handles a MVC request
  *
  * @param string $uri
  *
  * @return \ManaPHP\Http\ResponseInterface
  * @throws \ManaPHP\Mvc\Application\Exception
  * @throws \ManaPHP\Event\Exception
  * @throws \ManaPHP\Mvc\Application\NotFoundModuleException
  * @throws \ManaPHP\Mvc\Dispatcher\Exception
  * @throws \ManaPHP\Mvc\Dispatcher\NotFoundControllerException
  * @throws \ManaPHP\Mvc\Dispatcher\NotFoundActionException
  * @throws \ManaPHP\Mvc\View\Exception
  * @throws \ManaPHP\Renderer\Exception
  * @throws \ManaPHP\Alias\Exception
  * @throws \ManaPHP\Mvc\Router\Exception
  * @throws \ManaPHP\Mvc\Router\NotFoundRouteException
  */
 public function handle($uri = null)
 {
     if ($this->fireEvent('application:boot') === false) {
         return $this->response;
     }
     $this->router->handle($uri, null, false);
     $moduleName = ucfirst($this->router->getModuleName());
     $controllerName = $this->router->getControllerName();
     $actionName = $this->router->getActionName();
     $params = $this->router->getParams();
     $this->alias->set('@views', "@app/{$moduleName}/Views");
     $this->alias->set('@messages', "@app/{$moduleName}/Messages");
     $this->alias->set('@ns.module', '@ns.app\\' . $moduleName);
     $this->alias->set('@ns.controllers', '@ns.module\\Controllers');
     $this->alias->set('@ns.widgets', '@ns.module\\Widgets');
     $moduleClassName = $this->alias->resolve('@ns.module\\Module');
     $eventData = ['module' => $moduleName];
     $this->fireEvent('application:beforeStartModule', $eventData);
     $this->_moduleObject = $this->_dependencyInjector->getShared($moduleClassName);
     $this->_moduleObject->registerServices($this->_dependencyInjector);
     $eventData = ['module' => $moduleName];
     $this->fireEvent('application:afterStartModule', $eventData);
     $handler = [$this, '_eventHandlerBeforeExecuteRoute'];
     $this->dispatcher->attachEvent('dispatcher:beforeExecuteRoute', $handler);
     $ret = $this->dispatcher->dispatch($moduleName, $controllerName, $actionName, $params);
     if ($ret === false) {
         return $this->response;
     }
     $actionReturnValue = $this->dispatcher->getReturnedValue();
     if ($actionReturnValue === null || is_string($actionReturnValue)) {
         $this->view->setContent($actionReturnValue);
         $this->view->render($this->dispatcher->getControllerName(), $this->dispatcher->getActionName());
         $this->response->setContent($this->view->getContent());
     }
     return $this->response;
 }