isInstantiable()) { return new $nameBridge(); } return false; } static public function setDir($dirBridge){ if(!is_string($dirBridge)) { throw new \InvalidArgumentException('Dir bridge must be a string.'); } if(!file_exists($dirBridge)) { throw new \Exception('Dir bridge does not exist.'); } self::$dirBridge = $dirBridge; } static public function getDir(){ if(is_null(self::$dirBridge)) { throw new \LogicException(__CLASS__ . ' class need to know bridge path !'); } return self::$dirBridge; } /** * Lists the available bridges. * @return array List of the bridges */ static public function listBridges(){ $listBridge = array(); $dirFiles = scandir(self::getDir()); if($dirFiles !== false) { foreach($dirFiles as $fileName) { if(preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out)) { $listBridge[] = $out[1]; } } } return $listBridge; } static public function isWhitelisted($whitelist, $name){ return in_array($name, $whitelist) || in_array($name . '.php', $whitelist) || in_array($name . 'bridge', $whitelist) // DEPRECATED || in_array($name . 'bridge.php', $whitelist) // DEPRECATED || (count($whitelist) === 1 && trim($whitelist[0]) === '*'); } }