find command and match string

@param int $i
@param array $matches
@return array
181788
private function findCommand($i, array $matches)
    {
        $match = $matches[0][$i];
        $cmd = isset($matches['function'][$i]) ? $matches['function'][$i] : '';

        return [$match, $cmd];
    }
820274
private function getParametersFromMatchString($matchString, $pattern)
    {
        $parameters = [];
        $parameterIndices = $this->getMatchStringParameterIndices($matchString, $pattern);

        foreach ($parameterIndices as $position => $parameterIndex) {
            $start = $parameterIndex['index'];
            $foo = $position + 1;

            if (isset($parameterIndices[$position + 1])) {
                $length = $parameterIndices[$foo]['index'] - $start - strlen($parameterIndices[$foo]['prefix']);

                $parameters[] = substr($matchString, $start, $length);
            } else {
                $parameter = substr($matchString, $start);

                if (!empty($parameter)) {
                    $parameters[] = $parameter;
                }
            }
        }

        return $parameters;
    }
683225
public function match($patterns)
    {
        if (!is_array($patterns)) {
            $patterns = [$patterns];
        }

        $url = $this->getUrl();

        foreach ($patterns as $pattern) {
            $pattern = str_replace(['\\*', '\\?'], ['.+', '?'], preg_quote($pattern, '|'));

            if (preg_match('|^'.$pattern.'$|i', $url)) {
                return true;
            }
        }

        return false;
    }
2556
public function matches($key, $regex, &$matches = [])
    {
        if (!$this->has($key, self::HAS_ISSET)) {
            return false;
        }

        return (bool) preg_match($regex, $this->get($key), $matches);
    }
1166140
public function matchUrl(RequestInterface $request, array $maps)
    {
        $matched = [];

        $uri = (string)$request->getUri();

        /** @var RequestMap $map */
        foreach ($maps as $map) {
            if ((string)$map->getRequest()->getUri() === $uri) {
                $matched[] = $map;
            }
        }

        return $matched;
    }
383842
private function expandMatch(array $matches)
    {
        static $rfc1738to3986 = ['+' => '%20', '%7e' => '~'];

        $replacements = [];
        $parsed = self::parseExpression($matches[1]);
        $prefix = self::$operatorHash[$parsed['operator']]['prefix'];
        $joiner = self::$operatorHash[$parsed['operator']]['joiner'];
        $useQuery = self::$operatorHash[$parsed['operator']]['query'];

        foreach ($parsed['values'] as $value) {
            if (!isset($this->variables[$value['value']])) {
                continue;
            }

            $variable = $this->variables[$value['value']];
            $actuallyUseQuery = $useQuery;
            $expanded = '';

            if (is_array($variable)) {
                $isAssoc = $this->isAssoc($variable);
                $kvp = [];
                foreach ($variable as $key => $var) {
                    if ($isAssoc) {
                        $key = rawurlencode($key);
                        $isNestedArray = is_array($var);
                    } else {
                        $isNestedArray = false;
                    }

                    if (!$isNestedArray) {
                        $var = rawurlencode($var);
                        if ($parsed['operator'] === '+' ||
                            $parsed['operator'] === '#'
                        ) {
                            $var = $this->decodeReserved($var);
                        }
                    }

                    if ($value['modifier'] === '*') {
                        if ($isAssoc) {
                            if ($isNestedArray) {
                                // Nested arrays must allow for deeply nested
                                // structures.
                                $var = strtr(
                                    http_build_query([$key => $var]),
                                    $rfc1738to3986
                                );
                            } else {
                                $var = $key . '=' . $var;
                            }
                        } elseif ($key > 0 && $actuallyUseQuery) {
                            $var = $value['value'] . '=' . $var;
                        }
                    }

                    $kvp[$key] = $var;
                }

                if (empty($variable)) {
                    $actuallyUseQuery = false;
                } elseif ($value['modifier'] === '*') {
                    $expanded = implode($joiner, $kvp);
                    if ($isAssoc) {
                        // Don't prepend the value name when using the explode
                        // modifier with an associative array.
                        $actuallyUseQuery = false;
                    }
                } else {
                    if ($isAssoc) {
                        // When an associative array is encountered and the
                        // explode modifier is not set, then the result must be
                        // a comma separated list of keys followed by their
                        // respective values.
                        foreach ($kvp as $k => &$v) {
                            $v = $k . ',' . $v;
                        }
                    }
                    $expanded = implode(',', $kvp);
                }
            } else {
                if ($value['modifier'] === ':') {
                    $variable = substr($variable, 0, $value['position']);
                }
                $expanded = rawurlencode($variable);
                if ($parsed['operator'] === '+' || $parsed['operator'] === '#') {
                    $expanded = $this->decodeReserved($expanded);
                }
            }

            if ($actuallyUseQuery) {
                if (!$expanded && $joiner !== '&') {
                    $expanded = $value['value'];
                } else {
                    $expanded = $value['value'] . '=' . $expanded;
                }
            }

            $replacements[] = $expanded;
        }

        $ret = implode($joiner, $replacements);
        if ($ret && $prefix) {
            return $prefix . $ret;
        }

        return $ret;
    }
390986
public function match(array $matches) {
        $params = explode(' ', $matches[1]);
        $paramsNum = count($params);
        $this->params[] = $params[0];

        if (1 == $paramsNum) {
            return sprintf($this->defaultRegx['char'], '+');
        }
        else if (2 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], '+');
        }
        else if (3 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], $params[2] > 0 ? '{' . $params[2] . '}' : '*');
        }
        else if (4 == $paramsNum) {
            return sprintf($this->defaultRegx[$params[1]], '{' . $params[2] . ',' . $params[3] . '}');
        }
    }
1372187
public function getController($matches = [])
    {

        if (!isset($this->route['controller'])) {
            return false;
        }
        $controller = $this->route['controller'];
        preg_match("/.+?(?=Controllers)(.*)@/", $controller, $matches);
        if (!isset($matches[1])) {
            return false;
        }
        return str_ireplace(['Controllers', 'Controller', '\\'], "", $matches[1]);
    }
20355
private function _url(array $matches)
    {
        $params = [];
        if (isset($matches[2])) {
            parse_str($matches[2], $params);
        }
        foreach ($params as $key => $param) {
            if ($param == 'null') {
                $params[$key] = null;
            }
        }
        $https = null;
        $flags = (isset($matches[1]) ? $matches[1] : null);
        switch (substr_count($flags, '*')) {
            case 1:
                $https = false;
                break;
            case 2:
                $https = true;
                break;
        }
        return \Mmi\App\FrontController::getInstance()->getView()->getHelper('url')->url($params, true, $https);
    }
212798
function getMatchQuitters($matchId)
	{
		return $this->db->execute('SELECT login FROM Players WHERE matchId = %d AND (`state` = %d OR `state` = %d)',
                        $matchId,
                        PlayerInfo::PLAYER_STATE_QUITTER,
                        PlayerInfo::PLAYER_STATE_GIVE_UP)->fetchArrayOfSingleValues();
	}
1012407
protected function unquoteMatches(array $matches) {
        $newMatches = [];

        foreach ($matches as $match) {
            $newMatches[] = $this->unquoteMatch($match);
        }

        return $newMatches;
    }
341907
public function scan(&$i_iterator, $str_pattern = null, $i_count = null)
	{
        $argStrs = ['ARGV[1]'];
        $args = [$i_iterator];

        $argvCounter = 1;

        if(null !== $str_pattern)
        {
            $argStrs[] = "'MATCH'";
            $argStrs[] = 'ARGV[' . (++$argvCounter) . ']';
            $args[] = $str_pattern;
        }

        if(null !== $i_count)
        {
            $argStrs[] = "'COUNT'";
            $argStrs[] = 'ARGV[' . (++$argvCounter) . ']';
            $args[] = $i_count;
        }

        $argStr = implode(',', $argStrs);

        $result = $this->eval(<<<STR
return redis.call('scan', {$argStr}) 
STR
        , $args);

        if(!$result)
        {
            return false;
        }

        $i_iterator = (int)$result[0];
        return 0 === $i_iterator && [] === $result[1] ? false : $result[1];
	}
135884
private function getMatchArrayFromEnvironment($matchString)
    {
        $matches = array();
        foreach (explode(',', $matchString) as $etag) {
            $matches[] = trim($etag, '" ');
        }

        return $matches;
    }
586959
protected function fixMatches(
        /*# string */ $name,
        array $matches
    )/*# : array */ {
        $res = [];
        $map = $this->maps[$name];
        foreach ($matches as $idx => $val) {
            if ($idx > 0 && '' !== $val) {
                $res[$map[$idx - 1]] = $val;
            }
        }

        // debug
        $this->debug(Message::get(
            Message::DEBUG_MATCH_REGEX,
            $this->regex[$name]
        ));

        return [ $name, $res ];
    }
908699
protected function matchToKeys(array $matches)
    {
        $parameterNames = $this->parameterNames();

        if (count($parameterNames) == 0) {
            return array();
        }

        $parameters = array_intersect_key($matches, array_flip($parameterNames));

        return array_filter($parameters, function ($value)
        {
            return is_string($value) && (strlen($value) > 0);
        });
    }
1009846
protected static function expandMatch(array $matches)
    {
        $parsed = self::parseExpression($matches[1]);
        $replacements = [];

        $prefix = $parsed['operator'];
        $separator = $parsed['operator'];
        $queryStringShouldBeUsed = false;
        switch ($parsed['operator']) {
            case '?':
                $separator = '&';
                $queryStringShouldBeUsed = true;
                break;
            case '#':
                $separator = ',';
                break;
            case '&':
            case ';':
                $queryStringShouldBeUsed = true;
                break;
            case '+':
            case '':
                $separator = ',';
                $prefix = '';
                break;
        }

        foreach ($parsed['values'] as $value) {
            if (!array_key_exists($value['value'], self::$variables) || self::$variables[$value['value']] === null) {
                continue;
            }

            $variable = self::$variables[$value['value']];
            $useQueryString = $queryStringShouldBeUsed;

            if (is_array($variable)) {
                $expanded = self::encodeArrayVariable($variable, $value, $parsed['operator'], $separator, $useQueryString);
            } else {
                if ($value['modifier'] === ':') {
                    $variable = substr($variable, 0, $value['position']);
                }
                $expanded = rawurlencode($variable);
                if ($parsed['operator'] === '+' || $parsed['operator'] === '#') {
                    $expanded = self::decodeReservedDelimiters($expanded);
                }
            }

            if ($useQueryString) {
                if ($expanded === '' && $separator !== '&') {
                    $expanded = $value['value'];
                } else {
                    $expanded = $value['value'] . '=' . $expanded;
                }
            }

            $replacements[] = $expanded;
        }

        $result = implode($separator, $replacements);
        if ($result !== '' && $prefix !== '') {
            return $prefix . $result;
        }

        return $result;
    }
850574
public function matching ($pattern, &$matches = [], $flags = 0, $offset = 0, $start = 0, $end = null) {
		if (is_null($end)) {
			$end = $this->_length;
		}
		return static::Match($pattern, static::Substring($this->_string, $start, $end), $matches, $flags, $offset);
	}