Example #1
0
 /**
  * Find a configuration file and loads it.
  * Default configuration file is named 'propel' and is expected to be found in the current directory
  * or a subdirectory named '/conf' or '/config'. It can have one of the supported extensions (.ini, .properties,
  * .json, .yaml, .yml, .xml, .php, .inc).
  * Only one configuration file is supposed to be found.
  * This method also looks for a '.dist' configuration file and loads it.
  *
  * @param string $fileName  Configuration file name or directory in which resides the configuration file.
  * @param array  $extraConf Array of configuration properties, to be merged with those loaded from file.
  */
 protected function load($fileName, $extraConf)
 {
     $currentDir = getcwd();
     if (null === $fileName) {
         $fileName = self::CONFIG_FILE_NAME;
     }
     if (is_dir($fileName)) {
         $currentDir = $fileName;
         $fileName = 'propel';
     }
     if (null === $extraConf) {
         $extraConf = array();
     }
     if ('propel' === $fileName) {
         $dirs[] = $currentDir;
         if (is_dir($currentDir . '/conf')) {
             $dirs[] = $currentDir . '/conf';
         }
         if (is_dir($currentDir . '/config')) {
             $dirs[] = $currentDir . '/config';
         }
         $finder = new Finder();
         $finder->in($dirs)->depth(0)->files()->name($fileName . '.{php,inc,ini,properties,yaml,yml,xml,json}');
         $files = iterator_to_array($finder);
         $distfinder = new Finder();
         $distfinder->in($dirs)->depth(0)->files()->name($fileName . '.{php,inc,ini,properties,yaml,yml,xml,json}.dist');
         $distfiles = iterator_to_array($distfinder);
         $numFiles = count($files);
         $numDistFiles = count($distfiles);
         //allow to load only .dist file
         if (0 === $numFiles && 1 === $numDistFiles) {
             $files = $distfiles;
             $numFiles = 1;
         }
         if ($numFiles > 1) {
             throw new InvalidArgumentException('Propel expects only one configuration file');
         } elseif ($numFiles === 0) {
             $this->config = $extraConf;
             return;
         } else {
             $file = current($files);
             $fileName = $file->getPathName();
         }
     }
     $delegatingLoader = new DelegatingLoader();
     $conf = $delegatingLoader->load($fileName);
     $distConf = array();
     if (file_exists($fileName . '.dist')) {
         $distDelegatingLoader = new DelegatingLoader();
         $distConf = $distDelegatingLoader->load($fileName . '.dist');
     }
     $this->config = array_replace_recursive($distConf, $conf, $extraConf);
 }
 /**
  * Return the configuration array, loaded from $fileName
  *
  * @param string $fileName The configuration file
  *
  * @return array|mixed
  * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
  */
 private function loadFile($fileName)
 {
     if (!file_exists($fileName)) {
         return array();
     }
     $delegatingLoader = new DelegatingLoader();
     return $delegatingLoader->load($fileName);
 }