Пример #1
0
 /**
  * Set a given configuration value.
  *
  * @param array|string $key
  * @param mixed        $value
  *
  * @throws \InvalidArgumentException when key is null
  */
 public function set($key, $value = null)
 {
     if (is_null($key)) {
         throw new InvalidArgumentException('key should not be null');
     }
     if (is_array($key)) {
         foreach ($key as $innerKey => $innerValue) {
             Arr::set($this->items, $innerKey, $innerValue);
         }
     } else {
         Arr::set($this->items, $key, $value);
     }
 }
Пример #2
0
 /**
  * Load config from a single file and append it to config.
  *
  * @param string $path
  * @param array  $config
  *
  * @throws \Phig\Exceptions\FileNotFoundException      when path is not a file
  * @throws \Phig\Exceptions\ExtensionNotFoundException when path does not have an extension
  * @throws \UnexpectedValueException                   when file contents can not be resolved to an array
  *
  * @return array Updated config array
  */
 protected function loadPath($path, array $config)
 {
     if (!is_file($path)) {
         throw new FileNotFoundException($path);
     }
     if (strpos($path, '.') === false) {
         throw new ExtensionNotFoundException($path);
     }
     $parts = pathinfo($path);
     $extension = $parts['extension'];
     $filename = $parts['filename'];
     $contents = $this->getParser($extension)->parse($path);
     // treat values inside hidden files as "globals"
     if (!empty($filename) && $filename[0] !== '.') {
         $contents = [$filename => $contents];
     }
     if (!is_array($contents)) {
         throw new UnexpectedValueException("Config is not an array: {$path}");
     }
     $contents = Arr::dot($contents);
     foreach ($contents as $key => $value) {
         Arr::set($config, $key, $value);
     }
     return $config;
 }