Parse given options

@return self Returns itself

@throws Exception on error
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;
    }
305740
public function parse()
    {
        $annotations = ['rest' => []];
        foreach ($this->classes as $c) {
            $classAnnotations = $this->annotationsFromClass($c->getName())->toArray();
            if (isset($classAnnotations['rest'])) {
                $annotations['rest'] = array_merge($classAnnotations['rest'], $annotations['rest']);
            }
        }
        $annotations = new ConfigObject($annotations);

        $this->classDefaults = $annotations->get('rest', new ConfigObject([]));

        // get method annotations
        $annotations = ['rest' => [], 'param' => []];
        foreach ($this->classes as $c) {
            try {
                $methodAnnotations = $this->annotationsFromMethod($c->getName(), $this->method->name)->toArray();
            } catch (\Exception $e) {
                continue;
            }
            if (isset($methodAnnotations['rest']) && is_array($methodAnnotations['rest'])) {
                $annotations['rest'] = array_merge($methodAnnotations['rest'], $annotations['rest']);
            }
            if (isset($methodAnnotations['param'])) {
                if (is_array($methodAnnotations['param'])) {
                    $annotations['param'] = array_merge($methodAnnotations['param'], $annotations['param']);
                } else {
                    $annotations['param'][] = $methodAnnotations['param'];
                }

            }
        }

        $annotations = new ConfigObject($annotations);

        $restAnnotations = $annotations->get('rest', new ConfigObject([]));
        $paramAnnotations = $annotations->get('param', new ConfigObject([]));

        // check if we should ignore this method
        if ($restAnnotations->get('ignore', false) !== false) {
            return false;
        }

        // create ApiMethod instance
        $parsedMethod = new ParsedMethod($this->method->name);

        // method
        $parsedMethod->method = $this->getMethod($restAnnotations);
        // role
        $parsedMethod->role = $this->getRole($restAnnotations);
        // cache.ttl
        $parsedMethod->cache = $this->getCache($restAnnotations);
        // header.cache.expires
        $parsedMethod->header = $this->getHeader($restAnnotations);
        // default
        $parsedMethod->default = $this->getDefault($restAnnotations);
        // rateControl.ignore
        $parsedMethod->rateControl = $this->getRateControl($restAnnotations);

        // parse method parameters
        $parameterParser = new ParameterParser($this->method->getParameters(), $paramAnnotations);
        $parameters = $parameterParser->parse();
        foreach ($parameters as $p) {
            $parsedMethod->addParameter($p);
        }

        // build the url pattern
        if ($restAnnotations->get('url', false)) {
            // build url pattern using the provided rest.url pattern
            $urlPattern = $this->buildUrlPatternFromPattern($restAnnotations->get('url'), $parameters);
            $resourceNaming = true;
        } else {
            // build url pattern using method name and parameters
            $urlPattern = $this->buildUrlPatternStandard($this->method->name, $parameters);
            $resourceNaming = false;
        }

        $parsedMethod->setUrlPattern($urlPattern, $resourceNaming);

        return $parsedMethod;
    }
353121
public function parse()
	{
		if ($this->record->context instanceof \Exception)
		{
			$this->record->formatted = str_replace("{short-exc}", print_r($this->record->context->getMessage(), 1), $this->record->formatted);
		}
		return $this->record;
	}
444714
public function getOptionParser()
    {
        list($root, $name) = explode(' ', $this->name, 2);
        $parser = new ConsoleOptionParser($name);
        $parser->setRootName($root);

        $parser = $this->buildOptionParser($parser);
        if (!($parser instanceof ConsoleOptionParser)) {
            throw new RuntimeException(sprintf(
                "Invalid option parser returned from buildOptionParser(). Expected %s, got %s",
                ConsoleOptionParser::class,
                getTypeName($parser)
            ));
        }

        return $parser;
    }
392446
protected function parse()
    {
        $sectionName = static::GLOBAL_SECTION;
        $values = [];

        try {
            while ($line = fgets($this->handle)) {
                $this->linenumber++;
                $line = trim($line);
                if (empty($line) || substr($line, 0, 1) === ';') {
                    continue;
                }

                if ($this->isSectionHeader($line)) {
                    if ($sectionName === static::GLOBAL_SECTION) {
                        $this->config = $values;
                    } else {
                        $tokens = explode($this->delimiter, $sectionName);
                        $this->config = array_merge_recursive($this->config,
                                                              $this->subdivide($tokens, $values));

                        unset($tokens);
                    }

                    $sectionName = $this->getSectionHeader($line);
                    $values = [];
                    continue;
                }

                list($key, $value) = array_pad(preg_split(static::SPLIT_PATTERN, trim($line), 2), 2, '');

                if ($this->isArrayKey($key)) {
                    if (is_null($array_key = $this->parseArrayKey($key))) {
                        $key = trim(trim($key), '[]');

                        $values[$key][] = $this->parseValue($value);
                    } else {
                        $key = trim(substr($key, 0, strpos($key, '[')));
                        if (!isset($values[$key])) {
                            $values[$key] = [];
                        }

                        $values[$key][$array_key] = $this->parseValue($value);
                    }
                } else {
                    $values[trim($key)] = $this->parseValue($value);
                }
            }
        } catch (\Exception $ex) {
            throw new \RuntimeException("{$ex->getMessage()} Line: {$this->linenumber}.");
        } finally {
            $this->close();
        }

        if ($sectionName === static::GLOBAL_SECTION) {
            $this->config = $values;
        } else {
            $section = $this->subdivide(explode($this->delimiter, $sectionName), $values);
            $this->config = array_merge($this->config, $section);
        }
    }
818905
public function parse()
    {
        return $this->setDescription()
            ->setArray('IS_ARRAY')
            ->setOptional()
            ->setDefault()
            ->setRequired()
            ->calculateMode(InputArgument::class)
            ->setName();
    }
1131619
public static function parseOptions($definition)
    {
        preg_match_all('/m:([a-z-]+)(?:\(([^)]*)\))?/i', $definition, $matched, PREG_SET_ORDER);

        $result = [];
        foreach ($matched as $match) {

            if (array_key_exists($match[1], $result)) {
                throw new Exception\AnnotationException(
                    "Duplicate option '" . $match[1] . "'!"
                );
            }

            $result[$match[1]] = isset($match[2]) ? trim($match[2]) : null;
        }
        return $result;
    }
501653
public function parse()
    {
        // check if all requirements are fulfilled
        if (!$this->requirementsFulfilled()) {
            throw new Doozr_Di_Exception(
                'Error parsing constructor. Requirements not fulfilled. Please set input to parse constructor from.'
            );
        }

        // prepare input for parser
        $this->prepareInput();

        // if called from outside we maybe need a new instance of reflection
        if (!class_exists($this->input['className']) && !$this->input['reflection']) {
            throw new Doozr_Di_Exception(
                'Could not parse constructor! Please define at least a "file" which contains the className '.
                'or an existing ReflectionClass instance'
            );
        }

        // get reflection if not already passed to this method
        if (!$this->input['reflection']) {
            $reflectionClass = new ReflectionClass($this->input['className']);
        }

        // get filename of className
        if (!isset($this->input['file'])) {
            $this->input['file'] = $reflectionClass->getFileName();
        }

        // read the file as array
        $sourcecode = file($this->input['file']);

        // return the result
        return $this->parseTypehints($reflectionClass, $sourcecode);
    }
767482
public function parse(){
			$data = [];

			preg_match_all('#@(.*?)\n#s', $this->_comments, $annotations);

			foreach ($annotations[1] as $key => $annotation){
				if(preg_match('#([A-Za-z]+)\((.*)\)#is', $annotation)){
					preg_match_all('#([A-Za-z]+)\((.*)\)#is', $annotation, $annotationData);
					$annotationTitle = $annotationData[1][0];

					if(isset(Parser::$_annotations[$annotationTitle])) {
						$annotationContents = explode(", ", $annotationData[2][0]);
						$data[$key] = [];

						foreach ($annotationContents as $annotationContent) {
							preg_match_all('#(.+)="(.*)"#isU', trim($annotationContent), $annotationContentData);

							$data[$key]['type'] = $annotationTitle;
							$data[$key]['class'] = Parser::$_annotations[$annotationTitle];
							$data[$key]['properties'][$annotationContentData[1][0]] = $annotationContentData[2][0];
						}
					}
					else{
						throw new AnnotationNotExistingException('The annotation "' . $annotationTitle . '" does not exist');
					}
				}
			}

			return $data;
		}
792968
protected function parse()
    {
        $data = $this->_source->getData();

        $prefilters = $this->getPreFilterInstances();
        foreach($prefilters as $prefilter) {
            $data = $prefilter->filter($data);
        }

        $realpath = $this->_source->getRealPath();
        $parser = new PHPTAL_Dom_SaxXmlParser($this->_encoding);

        $builder = new PHPTAL_Dom_PHPTALDocumentBuilder();
        $tree = $parser->parseString($builder, $data, $realpath)->getResult();

        foreach($prefilters as $prefilter) {
            if ($prefilter instanceof PHPTAL_PreFilter) {
                if ($prefilter->filterDOM($tree) !== NULL) {
                    throw new PHPTAL_ConfigurationException("Don't return value from filterDOM()");
                }
            }
        }

        $state = new PHPTAL_Php_State($this);

        $codewriter = new PHPTAL_Php_CodeWriter($state);
        $codewriter->doTemplateFile($this->getFunctionName(), $tree);

        return $codewriter->getResult();
    }
39883
protected function parse(): array
    {
        $offset = 0;
        $name = $this->_parseName($offset);
        if ($offset < $this->_len) {
            $remains = substr($this->_dn, $offset);
            throw new \UnexpectedValueException(
                "Parser finished before the end of string" .
                     ", remaining: '$remains'.");
        }
        return $name;
    }
9220
public function extract()
    {
        if (!isset($this->config['sourcePath'], $this->config['languages'])) {
            throw new Exception('The configuration must specify "sourcePath" and "languages".');
        }

        foreach ($this->config['sourcePath'] as $sourcePath) {
            if (!is_dir($sourcePath)) {
                throw new Exception("The source path {$sourcePath} is not a valid directory.");
            }
        }

        if (empty($this->config['format']) || !in_array($this->config['format'], ['php', 'po', 'db'])) {
            throw new Exception('Format should be either "php", "po" or "db".');
        }
        if (in_array($this->config['format'], ['php', 'po'])) {
            if (!isset($this->config['messagePath'])) {
                throw new Exception('The configuration file must specify "messagePath".');
            } elseif (!is_dir($this->config['messagePath'])) {
                throw new Exception("The message path {$this->config['messagePath']} is not a valid directory.");
            }
        }
        if (empty($this->config['languages'])) {
            throw new Exception("Languages cannot be empty.");
        }

        $files = [];
        foreach ( $this->config['sourcePath'] as $sourcePath ) {
            $files = array_merge(
                array_values($files),
                array_values(FileHelper::findFiles(realpath($sourcePath), $this->config))
            );
        }

        $messages = [];
        foreach ($files as $file) {
            $messages = array_merge_recursive($messages, $this->extractMessages($file, $this->config['translator']));
        }
        if (in_array($this->config['format'], ['php', 'po'])) {
            foreach ($this->config['languages'] as $language) {
                $dir = $this->config['messagePath'] . DIRECTORY_SEPARATOR . $language;
                if (!is_dir($dir)) {
                    @mkdir($dir);
                }
                if ($this->config['format'] === 'po') {
                    $catalog = isset($this->config['catalog']) ? $this->config['catalog'] : 'messages';
                    return $this->saveMessagesToPO($messages, $dir, $this->config['overwrite'], $this->config['removeUnused'], $this->config['sort'], $catalog);
                } else {
                    return $this->saveMessagesToPHP($messages, $dir, $this->config['overwrite'], $this->config['removeUnused'], $this->config['sort']);
                }
            }
        } elseif ($this->config['format'] === 'db') {
            $db = \Yii::$app->get(isset($this->config['db']) ? $this->config['db'] : 'db');
            if (!$db instanceof \yii\db\Connection) {
                throw new Exception('The "db" option must refer to a valid database application component.');
            }
            $sourceMessageTable = isset($this->config['sourceMessageTable']) ? $this->config['sourceMessageTable'] : '{{%source_message}}';
            $messageTable = isset($this->config['messageTable']) ? $this->config['messageTable'] : '{{%message}}';
            return $this->saveMessagesToDb(
                $messages,
                $db,
                $sourceMessageTable,
                $messageTable,
                $this->config['removeUnused'],
                $this->config['languages']
            );
        }
    }
471299
protected function parse()
    {
        $parseOptions = true;
        $this->parsed = $this->tokenPairs;
        while (null !== $tokenPair = \array_shift($this->parsed)) {
            // token is what you'd expect. rest is the remainder of the input
            // string, including token, and will be used if this is a code arg.
            list($token, $rest) = $tokenPair;

            if ($parseOptions && '' === $token) {
                $this->parseShellArgument($token, $rest);
            } elseif ($parseOptions && '--' === $token) {
                $parseOptions = false;
            } elseif ($parseOptions && 0 === \strpos($token, '--')) {
                $this->parseLongOption($token);
            } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
                $this->parseShortOption($token);
            } else {
                $this->parseShellArgument($token, $rest);
            }
        }
    }
711154
public function parse($panic = false) {
        list($shorts, $longs) = $this->getOptionsSearchStrings();
        $options = getopt($shorts, $longs);
        $Exception = null;
        foreach ($this->parameters as $Option) {
            /** @var $Option Option */
            $short = $Option->getShort();
            $long = $Option->getLong();
            switch (true) {
                case isset($options[$short]) && isset($options[$long]):
                    throw new DuplicateOptionException();
                case isset($options[$short]):
                    $this->setOptionValue($Option, $this->getPreparedValue($options[$short]));
                    break;
                case isset($options[$long]):
                    $this->setOptionValue($Option, $this->getPreparedValue($options[$long]));
                    break;
                case $Option->isRequired():
                    $Exception = new RequiredOptionException($long);
            }
        }

        if ($panic && !is_null($Exception)) {
            throw $Exception;
        }
    }
532423
public function parseData(): self
    {
        if (!is_array($this->raw_data)) {
            throw new RuntimeException('Response must be an array');
        }

        if (!array_key_exists('status', $this->raw_data)) {
            $this->result_code = ResponseInterface::RESULT_DATA_MALFORMED;

            return $this;
        }

        $this->result_code = $this->raw_data['status'];

        // ios > 7 receipt validation
        if ($this->isIOS7StyleReceipt()) {
            $this->parseIOS7StyleReceipt();
        } elseif ($this->isIOS6StyleReceipt()) {
            $this->parseIOS6StyleReceipt();
        }

        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');
        }
    }
1161817
protected function parseOptions($options, $rootOption = [])
    {

        // @todo: need to make it is_iterable
        if (is_array($options)) {
            foreach ($options as $key => $option) {
                $options[$key] = $this->parseOptions($option, $rootOption);
            }
        } elseif (is_scalar($options)) {
            if (preg_match('/{{/', $options)) {
                foreach ($rootOption as $key => $value) {
                    if (is_scalar($value)) {
                        $options = str_replace('{{' . $key . '}}', $value, $options);
                    }
                }
                return $options;
            }
        }

        return $options;

    }