Пример #1
0
 /**
  * Loads a configuration file from a path.
  *
  * If the path does not exist, an empty configuration file is returned.
  *
  * @param string $path       The path to the configuration file.
  * @param Config $baseConfig The configuration that the loaded configuration
  *                           will inherit its values from.
  *
  * @return ConfigFile The loaded configuration file.
  *
  * @throws StorageException       If the file cannot be read.
  * @throws InvalidConfigException If the file contains invalid configuration.
  */
 public function loadConfigFile($path, Config $baseConfig = null)
 {
     if (!$this->storage->exists($path)) {
         return new ConfigFile($path, $baseConfig);
     }
     $serialized = $this->storage->read($path);
     return $this->serializer->unserializeConfigFile($serialized, $path, $baseConfig);
 }
Пример #2
0
 /**
  * Loads a configuration file from a path.
  *
  * If the path does not exist, an empty configuration file is returned.
  *
  * @param string      $path       The path to the configuration file.
  * @param Config|null $baseConfig The configuration that the loaded
  *                                configuration will inherit its values
  *                                from.
  *
  * @return ConfigFile The loaded configuration file.
  *
  * @throws FileNotFoundException  If the file does not exist.
  * @throws ReadException          If the file cannot be read.
  * @throws InvalidConfigException If the file contains invalid configuration.
  */
 public function loadConfigFile($path, Config $baseConfig = null)
 {
     $json = $this->storage->read($path);
     $jsonData = $this->decode($json, $path);
     try {
         return $this->configFileConverter->fromJson($jsonData, array('path' => $path, 'baseConfig' => $baseConfig));
     } catch (ConversionFailedException $e) {
         throw new InvalidConfigException(sprintf('The JSON in %s could not be converted: %s', $path, $e->getMessage()), 0, $e);
     }
 }
Пример #3
0
 private function loadFile($path, $className, array $options = array())
 {
     $json = $this->storage->read($path);
     $jsonData = $this->decode($json, $path);
     $options['path'] = $path;
     try {
         return $this->converterProvider->getJsonConverter($className)->fromJson($jsonData, $options);
     } catch (ConversionFailedException $e) {
         throw new InvalidConfigException(sprintf('The JSON in %s could not be converted: %s', $path, $e->getMessage()), 0, $e);
     }
 }