/** Return an instance of Router * @return Router */ public static function getInstance() { if (!isset(self::$instance)) { $config = FajrConfigLoader::getConfiguration(); $cachePath = $config->getDirectory(FajrConfigOptions::PATH_TO_ROUTER_CACHE); $controllerPath = FajrUtils::joinPath(FajrUtils::getProjectRootDirectory(), '/src/controller'); $locator = new FileLocator(array($controllerPath)); $request = SymfonyRequest::createFromGlobals(); $requestContext = new RequestContext(); $requestContext->fromRequest($request); $sfRouter = new SymfonyRouter(new YamlFileLoader($locator), "routes.yml", array('cache_dir' => $config->get(FajrConfigOptions::USE_CACHE) ? $cachePath : null), $requestContext); self::$instance = new Router($sfRouter, $request); } return self::$instance; }
/** * @returns string absolute path to configuration file */ public static function getConfigurationFileName() { return FajrUtils::joinPath(FajrUtils::getProjectRootDirectory(), '/config/configuration.php'); }
/** * Get a directory configuration path. * * If a relative path is given in configuration, it is resolved * relative to the specified directory or project root directory * if no directory was specified * * @param string $key * @returns string absolute path for the directory specified in configuration * or null if this option was not specified and does not have * a default value * @see FajrConfig::getParameterDescription() * @see configuration.example.php */ public function getDirectory($key) { $dir = $this->get($key); if ($dir === null) { return null; } if (FajrUtils::isAbsolutePath($dir)) { return $dir; } // default resolve relative $relativeTo = FajrUtils::getProjectRootDirectory(); $parameters = $this->getParameterDescription(); assert(array_key_exists($key, $parameters)); $param = $parameters[$key]; if (array_key_exists('relativeTo', $param)) { $relativeTo = $this->getDirectory($param['relativeTo']); } return FajrUtils::joinPath($relativeTo, $dir); }