public static function getInstance() { if (!isset(self::$instance)) { $config = FajrConfigLoader::getConfiguration(); $type = $config->get(FajrConfigOptions::DEBUG_TRACE); $uniqueID = sha1(uniqid('trace', true)); $header = 'Trace (id: ' . $uniqueID . ')'; $tags = array('unique-id' => $uniqueID); if ($type === FajrConfigOptions::DEBUG_TRACE_NONE) { self::$instance = new NullTrace(); } else { if ($type === FajrConfigOptions::DEBUG_TRACE_ARRAY) { self::$instance = new ArrayTrace(SystemTimer::getInstance(), $header); } else { // File-based trace $traceDir = $config->getDirectory(FajrConfigOptions::DEBUG_TRACE_DIR); if ($traceDir === null) { throw new \LogicException(FajrConfigOptions::DEBUG_TRACE_DIR . ' is not set, but is required for file-based traces'); } $ext = $type == FajrConfigOptions::DEBUG_TRACE_TEXT ? 'txt' : 'bin'; $filename = FajrUtils::joinPath($traceDir, 'trace' . $uniqueID . '.' . $ext); $file = @fopen($filename, 'ab'); if ($file === false) { throw new \Exception('Cannot open trace file'); } if ($type == FajrConfigOptions::DEBUG_TRACE_TEXT) { self::$instance = new FileTrace(SystemTimer::getInstance(), $file, 0, $header); } else { self::$instance = new BinaryFileTrace(SystemTimer::getInstance(), $file, $header, $tags); } } } } return self::$instance; }
public function getPath() { $dir = $this->config['path']; if (FajrUtils::isAbsolutePath($dir)) { return $dir; } // default resolve relative to Template.Directory $relativeTo = FajrConfig::getDirectory('Template.Directory'); return FajrUtils::joinPath($relativeTo, $dir); }
public function testJoinPath() { $DS = DIRECTORY_SEPARATOR; $this->assertEquals(FajrUtils::joinPath($DS, $DS), $DS, '/,/'); $this->assertEquals(FajrUtils::joinPath('foo', $DS), 'foo', 'foo,/'); $this->assertEquals(FajrUtils::joinPath($DS, 'foo'), $DS . 'foo', '/,foo'); $this->assertEquals(FajrUtils::joinPath($DS . 'foo' . $DS, 'bar'), $DS . 'foo' . $DS . 'bar', '/foo/,bar'); $this->assertEquals(FajrUtils::joinPath('foo', 'bar'), 'foo' . $DS . 'bar', 'foo,bar'); $this->assertEquals(FajrUtils::joinPath('foo' . $DS, $DS . 'bar'), 'foo' . $DS . 'bar', 'foo/,/bar'); $this->assertEquals(FajrUtils::joinPath($DS . 'foo' . $DS, $DS . 'bar' . $DS), $DS . 'foo' . $DS . 'bar' . $DS, '/foo/,/bar/'); $this->assertEquals(FajrUtils::joinPath('', ''), '', ','); $this->assertEquals(FajrUtils::joinPath($DS, 'foo', $DS, 'bar', $DS . 'baz'), $DS . 'foo' . $DS . 'bar' . $DS . 'baz', '/,foo,/,bar,/baz'); }
/** 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; }
/** * 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::$defaultOptions * @see FajrConfig::$directoriesRelativeTo * @see configuration.example.php */ public static function getDirectory($key) { self::assertInitialized(); $dir = self::get($key); if ($dir === null) { return null; } if (FajrUtils::isAbsolutePath($dir)) { return $dir; } // default resolve relative $relativeTo = FajrUtils::joinPath(dirname(__FILE__), '..'); $parameters = self::getParameterDescription(); assert(array_key_exists($key, $parameters)); $param = $parameters[$key]; if (array_key_exists('relativeTo', $param)) { $relativeTo = self::getDirectory($param['relativeTo']); } return FajrUtils::joinPath($relativeTo, $dir); }
/** * @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); }
public static function getInstance() { require_once FajrUtils::joinPath(__DIR__, '..', 'third_party', 'icalcreator', 'iCalcreator.class.php'); return new \vcalendar(); }
private function provideCookieFile() { return FajrUtils::joinPath($this->config->getDirectory('Path.Temporary.Cookies'), 'cookie_' . session_id()); }
private static function provideCookieFile() { $config = FajrConfigLoader::getConfiguration(); return FajrUtils::joinPath($config->getDirectory('Path.Temporary.Cookies'), 'cookie_' . session_id()); }