/** * @param string $path * @return Config * @throws \Exception */ public static function fromFile($path = 'snoauth-config.php') { if (!file_exists($path)) { throw new \Exception("No snoauth config file at '{$path}'", 500); } /** @noinspection PhpIncludeInspection */ include $path; if (!isset($config)) { throw new \Exception("No config variable found in snoauth config file at '{$path}'", 500); } // PDO if (!isset($config['db'])) { throw new \Exception("No db config Setting specified in snoauth config file at '{$path}'", 500); } // create Config $snoauthConfig = new Config(); $snoauthConfig->setConfigArray($config); return $snoauthConfig; }
/** * @param string $path * @return Config * @throws Exception */ public static function fromFile($path = 'frest-config.json') { $searchPath = $path; $numDirsUp = 0; $fileExists = file_exists($searchPath); // search for config file starting in current directory, going up to a possible of 3 directories while (!$fileExists && $numDirsUp <= 3) { $searchPath = '../' . $searchPath; $fileExists = file_exists($searchPath); $numDirsUp++; } if (!$fileExists) { throw new Exception(Exception::Config, "No config file found with name '{$path}'"); } $jsonConfigString = file_get_contents($searchPath); $config = json_decode($jsonConfigString, TRUE); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception(Exception::Config, "Config file is not valid json"); } // PDO if (!isset($config['db'])) { throw new Exception(Exception::Config, "No db config settings specified in frest config file at '{$path}'"); } // create Config $frestConfig = new Config(); $frestConfig->setConfigArray($config); return $frestConfig; }