Eva\EvaEngine\Engine::diRouter PHP Метод

diRouter() публичный Метод

public diRouter ( )
    public function diRouter()
    {
        $di = $this->getDI();
        $cachePrefix = $this->getAppName();
        $cacheFile = $this->getConfigPath() . "/_cache.{$cachePrefix}.router.php";
        if ($router = $this->readCache($cacheFile, true)) {
            return $router;
        }
        $moduleManager = $di->getModuleManager();
        $config = new Config();
        $moduleName = '';
        if ($moduleManager && ($modulesArray = $moduleManager->getModules())) {
            foreach ($modulesArray as $moduleName => $module) {
                //NOTICE: EvaEngine Load front-end router at last
                $config->merge(new Config($moduleManager->getModuleRoutesFrontend($moduleName)));
                $config->merge(new Config($moduleManager->getModuleRoutesBackend($moduleName)));
            }
        }
        //Disable default router
        $router = new Router(false);
        //Last extra slash
        $router->removeExtraSlashes(true);
        //Set last module as default module
        $router->setDefaultModule($moduleName);
        //NOTICE: Set a strange controller here to make router not match default index/index
        $router->setDefaultController('EvaEngineDefaultController');
        $config = $config->toArray();
        foreach ($config as $url => $route) {
            if (count($route) !== count($route, COUNT_RECURSIVE)) {
                if (isset($route['pattern']) && isset($route['paths'])) {
                    $method = isset($route['httpMethods']) ? $route['httpMethods'] : null;
                    $router->add($route['pattern'], $route['paths'], $method);
                } else {
                    throw new Exception\RuntimeException(sprintf('No route pattern and paths found by route %s', $url));
                }
            } else {
                $router->add($url, $route);
            }
        }
        if (!$di->getConfig()->debug) {
            $this->writeCache($cacheFile, $router, true);
        } else {
            //Dump merged routers for debug
            $this->writeCache($this->getConfigPath() . "/_debug.{$cachePrefix}.router.php", $router, true);
        }
        return $router;
    }