Ejemplo n.º 1
0
 /**
  * Iterate over framework detection commands to identify an appropriate
  * Envariable config loader and then load the config.
  *
  * @return array
  *
  * @throws \RuntimeException
  */
 public function loadConfigFile()
 {
     try {
         array_walk($this->frameworkConfigPathLocatorCommandList, array($this, 'frameworkConfigPathLocatorCallback'));
     } catch (\RuntimeException $runtimeException) {
         // Do nothing. Exiting array_walk as soon as a config has been loaded.
     }
     if (!$this->filesystem->fileExists($this->configPath)) {
         throw new \RuntimeException('Could not load Envariable config.');
     }
     $envariableConfigFilePath = sprintf('%s%sEnvariable%sconfig.php', $this->configPath, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
     if (!$this->filesystem->fileExists($envariableConfigFilePath)) {
         $this->configCreator->createConfigFile($envariableConfigFilePath);
     }
     return $this->filesystem->loadConfigFile($envariableConfigFilePath);
 }
Ejemplo n.º 2
0
 /**
  * @param \Envariable\DotEnvConfigProcessor|null $dotEnvConfigProcessor
  * @param \Envariable\ConfigLoader|null          $configLoader
  * @param \Envariable\EnvironmentDetector|null   $environmentDetector
  * @param \Envariable\Util\Server|null           $server
  * @param \Envariable\Util\Filesystem|null       $filesystem
  */
 public function __construct(DotEnvConfigProcessor $dotEnvConfigProcessor = null, ConfigLoader $configLoader = null, EnvironmentDetector $environmentDetector = null, Server $server = null, Filesystem $filesystem = null)
 {
     $this->dotEnvConfigProcessor = $dotEnvConfigProcessor ?: new DotEnvConfigProcessor();
     $this->configLoader = $configLoader ?: new ConfigLoader();
     $this->environmentDetector = $environmentDetector ?: new EnvironmentDetector();
     $this->server = $server ?: new Server();
     $this->filesystem = $filesystem ?: new Filesystem();
     $configCreator = new ConfigCreator();
     $configCreator->setFilesystem($this->filesystem);
     $this->configLoader->setFilesystem($this->filesystem);
     $this->configLoader->setConfigCreator($configCreator);
     $frameworkConfigPathLocatorCommandList = array(new CodeIgniterConfigPathLocatorCommand());
     foreach ($frameworkConfigPathLocatorCommandList as $command) {
         $command->setFilesystem($this->filesystem);
         $this->configLoader->addCommand($command);
     }
 }
Ejemplo n.º 3
0
 /**
  * Test that createConfigFile is called as envarible config file path does not exist.
  *
  * @param \Envariable\Util\Filesystem $filesystem
  * @param \Envariable\ConfigCreator   $configCreator
  */
 function it_will_call_createConfigFile_as_envariable_config_file_does_not_exist(Filesystem $filesystem, ConfigCreator $configCreator)
 {
     for ($i = 0; $i < count(self::$commandList); $i++) {
         $this->addCommand(self::$commandList[$i]);
     }
     $configDirectoryPath = 'path/to/config/directory';
     $envariableConfigFilePath = $configDirectoryPath . '/Envariable/config.php';
     $expectedResult = array('some-config-key' => 'some-config-value');
     $filesystem->fileExists($configDirectoryPath)->willReturn(true);
     $filesystem->fileExists($envariableConfigFilePath)->willReturn(false);
     $configCreator->createConfigFile($envariableConfigFilePath)->shouldBeCalled();
     $filesystem->loadConfigFile($envariableConfigFilePath)->willReturn($expectedResult);
     $this->setFilesystem($filesystem);
     $this->setConfigCreator($configCreator);
     $this->loadConfigFile()->shouldreturn($expectedResult);
 }