diff --git a/lib/Format.php b/lib/Format.php index b7d50910..5f1324c5 100644 --- a/lib/Format.php +++ b/lib/Format.php @@ -1,51 +1,129 @@ isInstantiable()) { + return new $name(); + } + + return false; } - public static function setDir($dirFormat){ - if(!is_string($dirFormat)) { + /** + * Sets the working directory. + * + * @param string $dir Path to a directory containing cache classes + * @throws \InvalidArgumentException if $dir is not a string. + * @throws \Exception if the working directory doesn't exist. + * @throws \InvalidArgumentException if $dir is not a directory. + * @return void + */ + public static function setWorkingDir($dir){ + self::$workingDir = null; + + if(!is_string($dir)) { throw new \InvalidArgumentException('Dir format must be a string.'); } - if(!file_exists($dirFormat)) { - throw new \Exception('Dir format does not exist.'); + if(!file_exists($dir)) { + throw new \Exception('Working directory does not exist!'); } - self::$dirFormat = $dirFormat; + if(!is_dir($dir)) { + throw new \InvalidArgumentException('Working directory is not a directory!'); + } + + self::$workingDir = $dir; } - public static function getDir(){ - $dirFormat = self::$dirFormat; - - if(is_null($dirFormat)) { - throw new \LogicException(__CLASS__ . ' class need to know format path !'); + /** + * Returns the working directory. + * The working directory must be set with {@see Format::setWorkingDir()}! + * + * @throws \LogicException if the working directory is not set. + * @return string The current working directory. + */ + public static function getWorkingDir(){ + if(is_null(self::$workingDir)) { + throw new \LogicException('Working directory is not set!'); } - return $dirFormat; + return self::$workingDir; } /** @@ -53,7 +131,7 @@ class Format { * @return array Informations about each format */ public static function searchInformation(){ - $pathDirFormat = self::getDir(); + $pathDirFormat = self::getWorkingDir(); $listFormat = array(); diff --git a/lib/rssbridge.php b/lib/rssbridge.php index 940913ee..74beb539 100644 --- a/lib/rssbridge.php +++ b/lib/rssbridge.php @@ -42,7 +42,7 @@ require_once PATH_LIB_VENDOR . 'php-urljoin/src/urljoin.php'; // Initialize static members try { Bridge::setWorkingDir(PATH_LIB_BRIDGES); - Format::setDir(PATH_LIB_FORMATS); + Format::setWorkingDir(PATH_LIB_FORMATS); Cache::setWorkingDir(PATH_LIB_CACHES); } catch(Exception $e) { error_log($e);