Esempio n. 1
0
 /**
  * \Scene\Config\Adapter\Ini constructor
  *
  * @param string $filePath
  * @throws Exception
  */
 public function __construct($filePath)
 {
     if (!is_string($filePath)) {
         throw new Exception('Invalid parameter type.');
     }
     if (!file_exists($filePath)) {
         throw new Exception('The file is not exists.');
     }
     $iniConfig = parse_ini_file($filePath, true);
     if ($iniConfig === false) {
         throw new Exception('Configuration file ' . $filePath . " can't be loaded");
     }
     $config = [];
     foreach ($iniConfig as $section => $directives) {
         if (is_array($directives)) {
             $sections = [];
             foreach ($directives as $path => $lastValue) {
                 $sections[] = $this->_parseIniString($path, $lastValue);
             }
             if (count($sections)) {
                 $config[$section] = call_user_func_array('array_merge_recursive', $sections);
             }
         } else {
             $config[$section] = $directives;
         }
     }
     parent::__construct($config);
 }
Esempio n. 2
0
 /**
  * Scene\Config\Adapter\Php constructor
  *
  * @param string $filePath
  */
 public function __construct($filePath)
 {
     if (!file_exists($filePath)) {
         throw new Exception('The file is not exists.');
     }
     parent::__construct(require $filePath);
 }
Esempio n. 3
0
 /**
  * \Scene\Config\Adapter\Json constructor
  *
  * @param string $filePath
  * @throws Exception
  */
 public function __construct($filePath)
 {
     if (!is_string($filePath)) {
         throw new Exception('Invalid parameter type.');
     }
     if (!file_exists($filePath)) {
         throw new Exception('The file is not exists.');
     }
     parent::__construct(json_decode(file_get_contents($filePath), true));
 }