Parse additional configuration files given as options

@return self Returns itself

@throws Exception on error
766028
protected function loadAdditionalConfigFiles() {
        $additionalConfigFiles = [];

        foreach ($this->config['options'] as $option => $value) {
            if (in_array($option, ['c', 'config'])) {
                switch (gettype($value)) {
                    case 'string':
                        $additionalConfigFiles[] = $value;
                        break;
                    case 'array':
                        foreach ($value as $item) {
                            if (!is_string($item)) {
                                throw new Exception(sprintf(
                                    'Unknown value "%s" for option "%s"',
                                    $item,
                                    $option
                                ), ExitApp::BAD_USER_INTERACTION);
                            }

                            $additionalConfigFiles[] = $item;
                        }
                        break;
                    default:
                        throw new Exception(sprintf(
                            'Unknown value "%s" for option "%s"',
                            $value,
                            $option
                        ), ExitApp::BAD_USER_INTERACTION);
                }
            }
        }

        foreach ($additionalConfigFiles as $additionalConfigFile) {
            $this->addConfigFile($additionalConfigFile);
        }

        return $this;
    }
488781
private function getConfiguration()
    {
        // Check for configuration option
        if ($this->configFile == null || !($this->configFile instanceof PhingFile)) {
            return null;
        }

        if (file_exists($this->configFile->__toString()) === false) {
            throw new BuildException(
                'The configuration file "' . $this->configFile->__toString() . '" doesn\'t exist.'
            );
        }

        if ($this->oldVersion) {
            $configurationClassName = 'PHP_Depend_Util_Configuration';
        } else {
            $configurationClassName = 'PDepend\\Util\\Configuration';
        }

        return new $configurationClassName(
            $this->configFile->__toString(),
            null,
            true
        );
    }
337405
def parse_config(file_path):
    """"""
    config_parser = configparser.ConfigParser()
    config_parser.read(file_path)
    plugin_config = {}
    options = config_parser.options(CONFIG_OPTION)
    for option in options:
        try:
            plugin_config[option] = config_parser.get(CONFIG_OPTION, option)
            if plugin_config[option] == -1:
                print("skip: %s" % option)
        except Exception as e:
            print("exception on %s!" % option)
            print(e.message)
            plugin_config[option] = None
    return plugin_config
1039965
public function parse() {
        global $argv;

        $options = array();
        $parameters = array();
        $argc = count( $argv );
        $paramCount = count( $this->parameters );
        
        //get parameters
        if( $argc - 1 < $paramCount ) {
            throw new \Exception("The command requires $paramCount parameters.");
        }
        
        //last items are the params
        for( $i = $paramCount - 1; $i >= 0; $i-- ) {
            $this->abstractParameters[$this->parameters[$i]] = $argv[$argc - $i - 1];
        }
        
        //go through each arg
        for( $i = 1; $i < $argc - $paramCount; $i++ ) {
            $arg = $argv[$i];
            
            //cannot start without a switch
            if( !$this->isOption( $arg ) ) {
                throw new \Exception("Invalid argument \"$arg\".");
            }
            
            //check if it's a valid option
            $option = $arg[1];

            if( $this->isParam( $option ) ) {
                //the arg stands on its own, such as -f, not -ffile.txt
                //set next as its value, move $i ahead
                if( $this->isSolitary( $arg ) ) {
                    //last item
                    if( $i == $argc - $paramCount - 1 ) {
                        throw new \Exception("Parameter does not follow the option \"$option\".");
                    }
                    
                    $this->abstractOptions[$option] = $argv[$i+1];
                    $i++;
                } else {
                    $this->abstractOptions[$option] = substr( $arg, 2 );
                }
            } else if( $this->isSwitch( $option ) ) {
                //loop through all switches in the param
                for( $i = 1; $i < strlen( $param ) - 1; $i++ ) {
                    $s = $arg[$i];
                    
                    //not a switch
                    if( !$this->isSwitch( $arg[$i] ) ) {
                        throw new \Exception("An invalid switch \"$s\" was provided.");
                    }
                    
                    $this->abstractOptions[$s] = true;
                }
            }
        }
    }
1095564
public function loadConfiguration()
    {
        if (!file_exists($this->path)) {
            return array();
        }
        
        if (!is_readable($this->path)) {
            throw new Exception('The file "' . $this->path . '" isn\'t readable!');
        }
        
        $content = file_get_contents($this->path);
        $settings = json_decode($content, true);

        if ($settings == false) {
            return array();
        }
        
        return $settings;
    }
84790
private function getSettings()
    {
        $rootPath = $this->complement['path']['root'];
        $configFile = $rootPath . 'config/';

        if (is_dir($configFile) && $handle = scandir($configFile)) {
            $files = array_slice($handle, 2);

            foreach ($files as $file) {
                $content = require $configFile . $file;
                $merge = array_merge($this->complement, $content);
                $this->complement = $merge;
            }
        }

        $this->complement['path']['root'] = $rootPath;
        $this->complement['path']['config'] = $configFile;
    }
951023
protected function parse()
    {
        // Try to parse and fail on any exception ...
        try {
            $this->getFlags()->parse();

            // Extract parsed arguments
            $this
                ->longs($this->getFlags()->longs())
                ->shorts($this->getFlags()->shorts())
                ->arguments($this->getFlags()->args());
        } catch (InvalidFlagParamException $e) {
            $this->showHelp($e->getMessage());
        } catch (InvalidFlagTypeException $e) {
            $this->showHelp($e->getMessage());
        }

        return $this;
    }
205481
public function parse_options()
    {
        $getopt = new Getopt([
            ['d', 'directory', Getopt::REQUIRED_ARGUMENT, 'Run under given directory'],
            ['l', 'level', Getopt::REQUIRED_ARGUMENT, 'Practice level on epic'],
            ['s', 'skip', Getopt::NO_ARGUMENT, 'Skip user input'],
            ['t', 'time', Getopt::REQUIRED_ARGUMENT, 'Delay each turn by seconds'],
            ['L', 'locale', Getopt::REQUIRED_ARGUMENT, 'Specify locale like en_US'],
            ['h', 'help', Getopt::NO_ARGUMENT, 'Show this message'],
        ]);
        try {
            $getopt->parse();
        } catch (\Exception $e) {
            echo $e->getMessage() . "\n";
            exit;
        }
        if ($getopt->getOption('h')) {
            echo $getopt->getHelpText();
            exit;
        }
        if ($getopt->getOption('d')) {
            Config::$path_prefix = $getopt->getOption('d');
        }
        if ($getopt->getOption('l')) {
            Config::$practice_level = $getopt->getOption('l');
        }
        if ($getopt->getOption('s')) {
            Config::$skip_input = true;
        }
        if (!is_null($getopt->getOption('t'))) {
            Config::$delay = $getopt->getOption('t');
        }
        // get locale from $LANG like en_US.UTF8
        list(Config::$locale) = explode('.', getenv('LANG'));
        if ($getopt->getOption('L')) {
            Config::$locale = $getopt->getOption('L');
        }
    }
87742
protected function parseContent()
    {
        $flatContent = implode($this->content);

        try {
            $parser = $this->getParser();
            $this->syntaxTree = $parser->parse($flatContent);
        } catch (Error $e) {
            throw new Exception('Error on parsing '.$this->classShortName." class\n".$e->getMessage());
        }

        return $this;
    }
1245187
protected function parseAll()
    {
        $this->display('* Parsing files');
        while ($file = $this->getFileToParse()) {
            $this->display(' -> Parsing '.$file.'...');
            // Process the file
            $rst = $this->getRST($file);
            $parser = new Parser(null, $this->kernel);

            $environment = $parser->getEnvironment();
            $environment->setMetas($this->metas);
            $environment->setCurrentFilename($file);
            $environment->setCurrentDirectory($this->directory);
            $environment->setTargetDirectory($this->targetDirectory);
            $environment->setErrorManager($this->errorManager);
            $environment->setUseRelativeUrls($this->relativeUrls);

            foreach ($this->beforeHooks as $hook) {
                $hook($parser);
            }

            if (!file_exists($rst)) {
                $this->errorManager->error('Can\'t parse the file '.$rst);
                continue;
            }

            $document = $this->documents[$file] = $parser->parseFile($rst);

            // Calling all the post-process hooks
            foreach ($this->hooks as $hook) {
                $hook($document);
            }

            // Calling the kernel document tweaking
            $this->kernel->postParse($document);

            $dependencies = $document->getEnvironment()->getDependencies();

            if ($dependencies) {
                $this->display(' -> Scanning dependencies of '.$file.'...');
                // Scan the dependencies for this document
                foreach ($dependencies as $dependency) {
                    $this->scan($dependency);
                }
            }

            // Append the meta for this document
            $this->metas->set(
                $file,
                $this->getUrl($document),
                $document->getTitle(),
                $document->getTitles(),
                $document->getTocs(),
                filectime($rst),
                $dependencies
            );
        }
    }
402915
protected function parseNameValue():self
	{
		$params= $this->line->pregGet('/ <(.*?)>(?= |$)/',1)
		 and $params= preg_split('/(?<!\\\\)\\|/',$params)
		  and array_map(function( $key, $value ){return isset($key)&&isset($value) ? $this->setAttribute($key,$this->checkExpression(str_replace('\\|','|',$value))) : '';},$this->config['name_value'],$params);

		return $this;
	}
520308
def parseconf (self, filename):
        """"""
        with open(filename) as fd:
            # yet another config format, sigh
            for line in fd:
                line = line.strip()
                if not line or line.startswith("#"):
                    # ignore empty lines and comments
                    continue
                split = line.split(None, 1)
                if len(split) == 1:
                    self[split[0]] = True
                else:
                    self[split[0]] = split[1]
647419
protected function parsePrivateAttributes():self
	{
		foreach( self::PRIVATE_ATTRIBUTES as $attribute ){
			isset($this->config[$attribute]) and $this->{'parse'.Helper\camel_case($attribute)}();
		}

		return $this;
	}
189226
protected function parseOptions() {
        $this->config['options'] = [];

        foreach ($this->options as $option) {
            $found = false;

            $types = [];

            if (array_key_exists('short', $option)) {
                $types['-'] = $option['short'];
            }

            if (array_key_exists('long', $option)) {
                $types['--'] = $option['long'];
            }

            foreach ($types as $prefix => $name) {
                $key = $prefix . $name;
                $value = null;

                for ($i = 1; $i < count($this->config['args']); $i++) {
                    if (strpos($this->config['args'][$i], $key, 0) === 0) {
                        switch ($option['value']) {
                            case self::NO_VALUE:
                                $value = true;
                                break;
                            case self::OPTION_REQUIRED:
                            case self::OPTION_NOT_REQUIRED:
                                if (strpos($this->config['args'][$i], $key . '=', 0) === 0) {
                                    $value = str_replace(
                                        $key . '=',
                                        '',
                                        $this->config['args'][$i]
                                    );
                                } elseif (array_key_exists(($i + 1), $this->config['args']) &&
                                    substr($this->config['args'][$i + 1], 0, strlen($prefix)) !== $prefix) {
                                    $value = $this->config['args'][$i + 1];
                                } else {
                                    throw new Exception(sprintf(
                                        'Option "%s" needs a value',
                                        $key
                                    ), ExitApp::BAD_USER_INTERACTION);
                                }
                                break;
                        }

                        if (array_key_exists($name, $this->config['options']) &&
                            !is_array($this->config['options'][$name])) {
                            $this->config['options'][$name] = [
                                $this->config['options'][$name],
                                $value
                            ];
                        } elseif (array_key_exists($name, $this->config['options']) &&
                            is_array($this->config['options'][$name])) {
                            $this->config['options'][$name][] = $value;
                        } else {
                            $this->config['options'][$name] = $value;
                        }

                        $found = true;
                    }
                }
            }

            if ($found === false && $option['value'] === self::OPTION_REQUIRED) {
                $message = '';

                if (array_key_exists('short', $option) && array_key_exists('long', $option)) {
                    $message = sprintf(
                        'Required option "-%s" or "--%s" is missing',
                        $option['short'],
                        $option['long']
                    );
                } elseif (array_key_exists('short', $option) && !array_key_exists('long', $option)) {
                    $message = sprintf(
                        'Required option "-%s" is missing',
                        $option['short']
                    );
                } elseif (!array_key_exists('short', $option) && array_key_exists('long', $option)) {
                    $message = sprintf(
                        'Required option "--%s" is missing',
                        $option['long']
                    );
                }

                throw new Exception($message, ExitApp::BAD_USER_INTERACTION);
            }
        }

        return $this;
    }
44677
private function readBundleConfiguration(): array
    {
        $configurationFilePath = $this->getApplicationDir() . '/config/bundles.yml';
        if (!is_readable($configurationFilePath)) {
            throw new \RuntimeException('The file "' . $configurationFilePath . '" could not be read.', 1504272377);
        }

        return Yaml::parse(file_get_contents($configurationFilePath));
    }
591046
protected function resolveConfigFile()
    {
        $ruleSet = $this->getInput()->getOption('ruleSet');

        if (null === $ruleSet && file_exists('phpsemver.xml')) {
            return 'phpsemver.xml';
        }

        if (null === $ruleSet) {
            $ruleSet = 'SemVer2';
        }

        if (file_exists($ruleSet)) {
            return $ruleSet;
        }

        $defaultPath = PHPSEMVER_LIB_PATH . '/PHPSemVer/Rules/';
        if (file_exists($defaultPath . $ruleSet . '.xml')) {
            return $defaultPath . $ruleSet . '.xml';
        }

        throw new \InvalidArgumentException(
            'Could not find rule set: ' . $ruleSet
        );
    }
1350793
protected function readConfig()
    {
        if ($this->_config === null) {
            $this->_config = [];
            foreach ($this->files as $file) {
                $path = Yii::getAlias($file);
                $path = FileHelper::normalizePath($path);
                if (is_file($path)) {
                    try {
                        /** @noinspection PhpIncludeInspection */
                        $this->_config[$file] = require $path;
                    } catch (Exception $exception) {
                        # Ignore
                    }
                }
            }
        }
        return $this->_config;
    }