Loads and parses the config file

@param string $env  Environment
@param string $file Config filename
@return void
@throws \Exception
546896
private function load($env = 'local', $file = 'config')
    {
        $path = BASE_PATH . ($file === '.env' ? '' : '/config');

        // File paths
        $configPath = "{$path}/{$file}.yml";
        $envConfigPath = "{$path}/{$file}_{$env}.yml";

        if (!file_exists($configPath)) {
            throw new \Exception("Config file not found at \"{$configPath}\".");
        }

        $data = file_get_contents($configPath);

        if ($data === false) {
            throw new \Exception("Unable to load configuration from: {$configPath}");
        }

        $yaml = new Parser();

        // Load config
        $config = $yaml->parse($data);
        $this->config = $config ? $config : [];

        // Load environment specific config
        if (file_exists($envConfigPath)) {
            $data = file_get_contents($envConfigPath);

            if ($data) {
                $config = $yaml->parse($data);
                $config = $config ? $config : [];

                // Merge config values
                $this->config = array_merge($this->config, $config);
            }
        }
    }
378988
private function loadEnvironment($env) {
    $this->exec = array_merge_recursive_distinct($this->exec, $this->environments[$env]);
    $this->loadedEnvs[$env] = $this->exec['filename'];
    unset($this->exec['filename']);
  }
238081
public function putEnvs(array $env)
    {
        foreach ($env as $key => $value) {
            $this->putEnv($key, $value);
        }
    }
555913
protected function parseSshConfigFile($file)
    {
        if (!file_exists($file) || !is_readable($file)) {
            throw new RuntimeException("The file '$file' does not exist or is not readable");
        }
        $contents = file_get_contents($file);
        $configs = array();
        $lineNumber = 1;
        foreach (explode(PHP_EOL, $contents) as $line) {
            $line = trim($line);
            if ($line == '' || $line[0] == '#') {
                continue;
            }
            $pos = strpos($line, '=');
            if ($pos !== false) {
                $key = strtolower(trim(substr($line, 0, $pos)));
                $value = trim(substr($line, $pos + 1, strlen($line)));
            } else {
                $i = 0;
                while ($i < strlen($line)) {
                    if ($line[$i] == ' ') {
                        break;
                    }
                    $i++;
                }
                if ($i == strlen($line)) {
                    throw new RuntimeException("The file '$file' is not parsable at line '$lineNumber'");
                }
                $key = strtolower(trim(substr($line, 0, $i)));
                $value = trim(substr($line, $i + 1, strlen($line)));
            }
            if ($key == 'host') {
                $this->configs = array_merge($this->configs, $configs);
                $configs = array();
                $hosts = explode(' ', $value);
                foreach ($hosts as $host) {
                    $configs[] = array('host' => $host);
                }

            } else {
                foreach ($configs as $host => $config) {
                    $configs[$host][$key] = $value;
                }
            }
            $lineNumber++;
        }
        $this->configs = array_merge($this->configs, $configs);
    }
256195
public function loadConfigurationFile($file = null)
    {
        $file = $file ?: $this->findConfigurationFile();
        if (! file_exists($file))
            return;

        $this->config = $this->yaml->load($file);
    }
62761
public function setEnvironment($env)
    {
        Assert::oneOf($env, Environment::all(), 'The environment must be one of: %2$s. Got: %s');

        $this->env = $env;
    }
1334355
public static function load($path)
    {
        if (is_dir($path)) {
            foreach (preg_grep('/^\.env$/', scandir($path)) as $filename) {
                $filePath = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
                if (is_readable($filePath)) {
                    foreach (parse_ini_file($filePath) as $envKey => $envValue) {
                        putenv($envKey . '=' . $envValue);
                    }
                }
            }
        } else {
            throw new BaseException('Your path does not directory.');
        }
    }
1089510
public static function setFile($file)
    {
        if (is_file($file)) {
            $options = Yaml::parse(file_get_contents($file));
            self::$instance = new self($options);
            self::$instance->validateOptions();
        } else {
            throw new Exception("Can't find config file at ".$file);
        }
    }
989593
public function load()
    {
        if (!is_file($this->filename)) {
            throw new \Mix\Exception\ConfigException("Environment file does not exist: {$this->filename}");
        }
        $this->_data = array_merge(parse_ini_file($this->filename), $_SERVER, $_ENV);
        return true;
    }
94238
public function load($file)
    {
        $loader = new PhpConfig();
        $widgets = $loader->read($file);
        $this->add($widgets);
    }
539269
public function setEnv($env = null)
    {
        if (in_array($env, \WebServCo\Framework\Environment::getOptions())) {
            $this->env = $env;
        } else {
            $this->env = \WebServCo\Framework\Environment::ENV_DEV;
        }

        return true;
    }
1304407
public function parse($resource, $output)
    {
        printf('file %s' . PHP_EOL, $resource);

        $pathinfo = pathinfo($resource);
        $extension = $pathinfo['extension'];

        $this->environment->setSourceFile($resource);

        $parser = $this->configuration->getParserForFileExtension($extension);

        if (!$parser instanceof ParserInterface) {
            throw new \Exception('No parser found. Have you initialized any plugins?');
        }

        if ($parser instanceof HasEnvironmentInterface) {
            $parser->setEnvironment($this->environment);
        }

        $content = $parser->parse($resource);
        $output  = $parser->getOutputFilename($output);
        file_put_contents($output, $content);
    }
873456
protected function _loadConfig($file) {
        $suffix = pathinfo($file, PATHINFO_EXTENSION);
        $suffix = ($suffix === 'dist') ?
                    pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION) : $suffix;
        if ($suffix == 'ini') {
            $config = Garp_Config_Ini::getCached($file, $this->getEnvironment())->toArray();
        } else {
            $config = parent::_loadConfig($file);
        }
        return $config;
    }
1218869
protected function initConfig($environment)
    {
        $this->logger->debug("Initializing '$environment' config");

        $configFile = $this->getConfigFile($environment);
        if (!file_exists($configFile)) {
            $this->logger->warning("Could not find $configFile");

            return;
        }

        $folderName = $this->getImporterFolderName($environment);
        $this->createConfigFolder($folderName);

        $modules = $this->getYamlManipulator()->parseYamlModules($configFile);

        $this->logger->debug('Checking modules');
        // check if we can safely move all the config. This has to be done first to make sure the Symfony config does not break.
        foreach ($modules as $module => $data) {
            if ('imports' === $module) {
                continue;
            }

            if (!$this->checkCanCreateModuleConfig($module, $environment)) {
                $filename = $this->stripBaseConfigFolderFromPath($configFile);
                throw new ModuleExistsException("Cannot move config module '{$module}' from file config/{$filename} to file config/{$folderName}{$module}.yml because it already exists and contains YAML data. Please clean up manually and retry.");
            }
        }

        $newConfig = array(
            'imports' => isset($modules['imports']) ? $modules['imports']['data']['imports'] : array(),
        );

        $this->logger->debug('Found '.count($modules).' modules inside config file: "'.implode(', "', array_keys($modules)).'"');

        $this->logger->debug('Adding modules to separated config files');
        foreach ($modules as $module => $data) {
            if ('imports' === $module) {
                continue;
            }

            $this->addModuleConfig($module, $data['content'], $environment, false, false);

            $filename = $this->getModuleFile($module, $environment, false);
            if (!$this->getYamlManipulator()->dataContainsImportFile($newConfig, $filename)) {
                $newConfig['imports'][] = array('resource' => $filename);
            }
        }

        $newConfig = $this->getYamlManipulator()->sortImports($newConfig, $folderName);

        $this->logger->debug("Re-writing $configFile");
        file_put_contents($configFile, Yaml::dump($newConfig));
    }
1124138
private function createEnv(): void
    {
        if (file_exists(base_dir('.env'))) {
            $dotEnv = new Dotenv();
            $dotEnv->load(base_dir('.env'));
            $this->env = $dotEnv;
        }
    }
769894
protected function mergeExternalFiles(string $file, MutableBag $envs): MutableBag
    {
        $extPos = strrpos($file, '.');
        $pathTemplate = substr_replace($file, '.%s.', $extPos, 1);
        foreach ($envs as $name => $config) {
            // config.yml -> config.production.yml
            $envFile = sprintf($pathTemplate, $name);
            if (!is_readable($envFile)) {
                continue;
            }
            $envConfig = $this->parse($envFile);
            $envs[$name] = $config->replaceRecursive($envConfig);
        }

        return $envs;
    }
392080
public function load($file)
	{
		if(!$this->fs->exists($file))
		{
			throw new Exceptions\FileNotExists($file);
		}

		$this->file = $file;
		$this->info->load($file);
		$this->extension = $this->info->extension;
		$this->directory = $this->info->directory;
		$this->filename = $this->info->filename;

		$this->extracter->load($file, $this->extension)
						->extract();

		$this->params = $this->extracter->params();
	}