Parses a short option token and returns an array of data

@param string $token The token to parse
@return array The name of the option mapped to its value
@throws RuntimeException Thrown if the option could not be parsed
324858
protected function parseShortOption(string $token) : array
    {
        if (mb_substr($token, 0, 1) !== '-') {
            throw new RuntimeException("Invalid short option \"$token\"");
        }

        // Trim the "-"
        $token = mb_substr($token, 1);

        $options = [];

        // Each character in a short option is an option
        $tokens = preg_split('//u', $token, -1, PREG_SPLIT_NO_EMPTY);

        foreach ($tokens as $singleToken) {
            $options[] = [$singleToken, null];
        }

        return $options;
    }
1369896
private function parseShortOptionSet($name)
    {
        $len = \strlen($name);
        for ($i = 0; $i < $len; ++$i) {
            if (!$this->definition->hasShortcut($name[$i])) {
                $encoding = mb_detect_encoding($name, null, true);
                throw new RuntimeException(sprintf('The "-%s" option does not exist.', false === $encoding ? $name[$i] : mb_substr($name, $i, 1, $encoding)));
            }

            $option = $this->definition->getOptionForShortcut($name[$i]);
            if ($option->acceptValue()) {
                $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));

                break;
            } else {
                $this->addLongOption($option->getName(), null);
            }
        }
    }
40725
public function fromString($token)
    {
        $segments = explode('.', $token);

        if (count($segments) == 3)
        {
            list($header, $payload, $signature) = $segments;

            $this->_header    = $this->_fromJson($this->_fromBase64url($header));
            $this->_claims    = $this->_fromJson($this->_fromBase64url($payload));
            $this->_signature = $this->_fromBase64url($signature);

            if(isset($this->_header['alg'])) {
                $this->setAlgorithm($this->_header['alg']);
            } else {
                $this->setAlgorithm('none');
            }
        }
        else throw new InvalidArgumentException(sprintf('The token "%s" is an invalid JWT', $token));

        return $this;
    }
862702
public static function getSpaceFromToken($token) {
        $pieces = explode('::', $token);
        if ( count($pieces) != 4 ) return false;
        $space = implode('::', array_slice($pieces,0,2));
        return $space;
    }
285326
public function getNextState($token)
    {
        foreach ($this->states as $mask => $state) {
            if ($mask & $token) {
                return $state;
            }
        }

        throw new RuntimeException("The supplied token: {$token} has no target state");
    }
530865
public function decode($token)
    {
        $decoded = json_decode($token, true);

        if (is_array($decoded) === true &&
            array_key_exists(self::KEY_USER_ID, $decoded) === true &&
            array_key_exists(self::KEY_SECRET, $decoded) === true
        ) {
            $token  = $decoded[self::KEY_SECRET];
            $userId = intval($decoded[self::KEY_USER_ID]);
            /** @var User $user */
            $user   = (new User())->query()->find($userId);

            if ($user !== null && $user->{User::FIELD_API_TOKEN} === $token) {
                $account = new Account($user, [Account::ATTR_ID => $userId]);

                $this->getLogger()->debug('Account authenticated.', [User::FIELD_ID => $userId]);

                return $account;
            }
        }

        return new Anonymous();
    }
33798
protected function getTokenFormatter($token)
    {
        $formatters = $this->getTokenFormatters();

        if (!array_key_exists($token, $formatters)) {
            $message = "The class %s does not know how to format the %s token\n".
                       "Have you added it in the getTokenFormatters() method?";

            throw new Exception(sprintf($message, get_called_class(), $token));
        }

        return $formatters[$token];
    }
1252484
public function addToken($token)
    {
        if (count($this->tokens) + 1 > self::MULTICAST_MAX_TOKENS) {
            throw new \RuntimeException(sprintf('Max token number reached. %s tokens max.', self::MULTICAST_MAX_TOKENS));
        }

        return parent::addToken($token);
    }
1360686
protected function parseToken($token)
    {
        [$id, $content] = $token;

        if ($id == T_INLINE_HTML) {
            foreach ($this->compilers as $type) {
                $content = $this->{"compile{$type}"}($content);
            }
        }

        return $content;
    }
620155
public function parse(Token $token): Node
    {
        $stream = $this->parser->getStream();

        $stream->expect(Token::BLOCK_END_TYPE);

        $body = $this->parser->subparse(function (Token $token): bool {
            return $token->test('endoptional');
        }, true);

        $stream->expect(Token::BLOCK_END_TYPE);

        return new OptionalNode($body, $token->getLine(), $this->getTag());
    }
988899
protected function tokenize($string)
    {
        $string = preg_replace('(\\r\\n|\\r)', "\n", $string);
        $tokens = array();
        $line = 1;

        while (strlen($string)) {
            foreach ($this->tokenSpecifications as $token => $regexp) {
                if (!preg_match($regexp, $string, $matches)) {
                    continue;
                }

                // Remove matched string
                $string = substr($string, strlen($matches[0]));
                $line += substr_count($matches[0], "\n");

                // Append token to list
                $tokens[] = array(
                    'type' => $token,
                    'data' => $this->filterValues($matches),
                );

                // Continue with outer loop
                continue 2;
            }

            throw new RuntimeException("Parse error in line $line: " . substr($string, 0, 100));
        }

        return $tokens;
    }
975920
private function decodeToken(string $token): array
    {
        try {
            $decoded = JWT::decode(
                $token,
                $this->options["secret"],
                (array) $this->options["algorithm"]
            );
            return (array) $decoded;
        } catch (Exception $exception) {
            $this->log(LogLevel::WARNING, $exception->getMessage(), [$token]);
            throw $exception;
        }
    }
1217110
public function getContentUntil(AbstractToken $token)
    {
        if ($this === $token) {
            return '';
        }

        $content = $this->getContent();
        $next = $this->nextToken;

        while ($next && $next !== $token) {
            $content .= $next->getContent();
            $next = $next->nextToken;
        }

        if (null === $next) {
            throw new \RuntimeException(sprintf('Could not find token "%s".', $token));
        }

        return $content;
    }
1212134
protected function getUserByToken($token)
    {
        \Php\Support\Helpers\Arr::arrayReplaceByTemplate($this->guzzle, ['{{%TOKEN%}}' => $token]);

        $response = $this->getHttpClient()->get($this->getDriverConfig('userInfoUrl'), $this->guzzle);

        return json_decode($response->getBody(), true);
    }
57220
protected static function parseArgument($token)
    {
        $description = null;

        if (mb_strpos($token, ' : ') !== false) {
            list($token, $description) = explode(' : ', $token, 2);

            $token = trim($token);

            $description = trim($description);
        }

        switch (true) {
            case Text::endsWith($token, '?*'):
                return new InputArgument(trim($token, '?*'), InputArgument::IS_ARRAY, $description);
            case Text::endsWith($token, '*'):
                return new InputArgument(trim($token, '*'), InputArgument::IS_ARRAY | InputArgument::REQUIRED, $description);
            case Text::endsWith($token, '?'):
                return new InputArgument(trim($token, '?'), InputArgument::OPTIONAL, $description);
            case preg_match('/(.+)\=(.+)/', $token, $matches):
                return new InputArgument($matches[1], InputArgument::OPTIONAL, $description, $matches[2]);
            default:
                return new InputArgument($token, InputArgument::REQUIRED, $description);
        }
    }
679571
public function decode($token)
    {
        try {
            $jwt = $this->parser->parse($token);
        } catch (Exception $e) {
            throw new TokenInvalidException('Could not decode token: '.$e->getMessage(), $e->getCode(), $e);
        }

        if (! $jwt->verify($this->signer, $this->getVerificationKey())) {
            throw new TokenInvalidException('Token Signature could not be verified.');
        }

        return (new Collection($jwt->getClaims()))->map(function ($claim) {
            return is_object($claim) ? $claim->getValue() : $claim;
        })->toArray();
    }
1154071
private function parseShortOption($arg)
    {
        $shortOptions = $this->shortOptions;

        // If our program does not accept short options
        // ignore current keyword
        if (empty($shortOptions)) {
            $this->optind++;
            return null;
        }

        // We do not accept single letter options with '=' (format -o=value)
        if (is_numeric(strpos($arg, '='))) {
            $this->optind++;
            return null;
        }

        // We must accept grouped option (eg. -cvd)
        $key = substr($arg, 1);

        if (strlen($key) > 1) {
            // We are parsing an option group
            return $this->parseShortOptionGroup($key);
        }

        // Deal with a single-char option, no option group
        if (strlen($key) == 1) {
            // Check if option is allowed
            $cpos = strpos($shortOptions, $key);

            // Invalid option, go to next
            if (false === $cpos) {
                $this->optind++;
                return null;
            }

            // Option is supported, go ahead
            $option = $key;

            // Check if option allows parameters
            if (isset($shortOptions[$cpos+1]) && $shortOptions[$cpos+1] === ':') {
                // Ok, parse parameter
                
                if ($this->optind < $this->argc -1) {
                    // Get next arg from our copy of $argv
                    $optarg = $this->argv[$this->optind + 1];

                    // If arg is not an option (should not begin with - or --)
                    if (!(substr($optarg, 0, 2) === '--') && !(substr($optarg, 0, 1) === '-')) {
                        // Option value is ok, set it and update index by 2 steps
                        $this->optarg = $optarg;
                        $this->optind += 2;
                        return $option;
                    }

                }

                // Option value missing, set it to FALSE and update index by 1 step only
                $this->optarg = false;
                $this->optind++;
                return $option;

            }

            // No parameter
            // In any case we now have a supported option
            $this->optarg = true;
            $this->optind++;
            return $option;

        }

        // Invalid option, go to next
        $this->optind++;
        return null;
    }