public function forwardToRoute($routeName, $vars = null) { if ($route = DC::getRouter()->getRoute($routeName)) { DC::getRouter()->setCurrentRoute($route)->getCurrentRequest()->setUri($route->buildUri($vars)); $route = new ApplicationRoute($route); DC::getApplication()->setRoute($route); ControllerService::processControllerAction($route->getControllerName(), $route->getActionName()); } }
public function detectApplication() { DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest()); $this->_name = 'console'; $this->_config = array('uri' => 'solve/', 'path' => 'SolveConsole/'); $this->_namespace = 'SolveConsole'; $this->_root = realpath(__DIR__ . '/../SolveConsole/') . '/'; DC::getAutoloader()->registerNamespacePath($this->_namespace, realpath(__DIR__ . '/../') . '/'); ControllerService::setActiveNamespace($this->_namespace); return $this->_name; }
public static function notFoundAction() { echo "command not found\n\n"; ControllerService::processControllerAction('IndexController', 'defaultAction'); }
public function detectApplication() { DC::getEventDispatcher()->dispatchEvent('route.buildRequest', Request::getIncomeRequest()); /** * @var ArrayStorage $appList */ $appList = DC::getProjectConfig('applications'); if (empty($appList)) { throw new \Exception('Empty application list'); } $defaultAppName = DC::getProjectConfig('defaultApplication', 'frontend'); $this->_name = $defaultAppName; $uri = (string) Request::getIncomeRequest()->getUri(); $uriParts = explode('/', $uri); $webRoot = DC::getRouter()->getWebRoot(); if (strlen($webRoot) > 1) { if (strpos($uri, substr($webRoot, 1)) === 0) { $uriParts = explode('/', substr($uri, strlen($webRoot))); } } if (!empty($uriParts) && (count($uriParts) > 0 && $uriParts[0] != '/')) { foreach ($appList as $appName => $appParams) { if ($appName == $defaultAppName) { continue; } $appUri = !empty($appParams['uri']) ? $appParams['uri'] : $appName; if (strpos($uriParts[0], $appUri) === 0) { array_shift($uriParts); Request::getIncomeRequest()->setUri((strlen($webRoot) > 1 ? $webRoot . '/' : '') . implode('/', $uriParts)); $this->_name = $appName; break; } } } $this->_config = DC::getProjectConfig('applications/' . $this->_name); if (!is_array($this->_config)) { $this->_config = array('uri' => $this->_name); } if (empty($this->_config['path'])) { $this->_config['path'] = Inflector::camelize($this->_name) . '/'; } $this->_namespace = Inflector::camelize($this->_name); $this->_root = DC::getEnvironment()->getApplicationRoot() . $this->_config['path']; DC::getAutoloader()->registerNamespacePath($this->_namespace, DC::getEnvironment()->getApplicationRoot()); ControllerService::setActiveNamespace($this->_namespace); return $this->_name; }