Get the next token and the token type and store it in cache.

@param string $string
@param string $token
@param string $cacheKey

@return array
779032
protected function getNextTokenFromString($string, $token, $cacheKey)
    {
        $token = $this->parseNextToken($string, $token);

        if ($cacheKey && \strlen($token[self::TOKEN_VALUE]) < $this->maxCacheKeySize) {
            $this->tokenCache[$cacheKey] = $token;
        }

        return $token;
    }
852603
public function get($cacheKey)
    {
        // TODO: Refactor for strict types!
        $path = $this->resolvePath($cacheKey, false);
        if (file_exists($path)) {
            return file_get_contents($path);
        }

        return null;
    }
931408
public static function getPayload(string $token, string $secret): array
    {
        $parser = self::parser($token, $secret);

        return $parser->validate()->parse()->getPayload();
    }
1033224
private function loadToken(TokenType $type)
    {
        // take from cache, filesystems are slow
        if (isset($this->cache[$type->toString()])) {
            return $this->cache[$type->toString()];
        }

        $token = trim(file_get_contents($this->path . '/' . $type->toString()));

        if (!$token) {
            throw new TokenNotFoundException($type, $this->path);
        }

        // save the result in the cache
        $this->cache[$type->toString()] = $token;

        return $token;
    }
1290746
public function getToken(TokenContext $context)
    {
        $getTokenCallback = $this->callbackFunc;
        $jwtString = $getTokenCallback($context);

        return Jwt::fromString($jwtString);
    }
693570
public function getTokenFromString($noisedToken, $key)
    {
        $date       = substr($noisedToken, 0, self::DATE_LENGTH);
        $tokenValue = substr($noisedToken, self::DATE_LENGTH, -$this->config['hash']['noise.length']);
        $noise      = substr($noisedToken, -$this->config['hash']['noise.length']);
        return new Token($this->config['type'], $key, $this->unformatDate($date), $tokenValue, $noise);
    }
582175
function(token) {
  if (token === undefined || token === null) {
    return {
      nextPartitionKey: undefined,
      nextRowKey:       undefined,
    };
  }
  assert(typeof token === 'string', 'Continuation token must be a string if ' +
                                     'not undefined');
  // Split at tilde (~)
  token = token.split('~');
  assert(token.length === 2, 'Expected an encoded continuation token with ' +
                             'a single tilde as separator');
  return {
    nextPartitionKey: decodeURIComponent(token[0]),
    nextRowKey:       decodeURIComponent(token[1]),
  };
}
716762
protected function getTokenFromCache()
    {
        if (!$this->cache || !$this->cache->hasItem(self::TOKEN_CACHE_KEY)) {
            return null;
        }

        /** @var Token $token */
        $token = $this->cache->getItem(self::TOKEN_CACHE_KEY)->get();

        if (!$token || !$token->getAuth()) {
            $this->logger->debug('No token in cache or auth is empty, returning null.');

            return null;
        }

        // invalidate token
        if ($this->isTokenExpired($token)) {
            $this->logger->debug('Token is expired.');

            $this->writeTokenInfoToDebugLog();

            return null;
        }

        return $token;
    }
1036884
public String generateTemporaryToken(String key, int secondsToLive, Object context) {
    checkNotNull(key);
    String token = tokenGenerator.generate();
    tokenCache.put(key, Triplet.of(token, DateTime.now().plusSeconds(secondsToLive).getMillis(), context));
    return token;
  }
139908
public function getTokens($type) {
        $tokens = $this->client->tokens(array('type' => implode('|', $type)));
        if (!empty($tokens['warnings']) || empty($tokens['tokens'])) {
            throw new SessionException("Error while getting tokens from wiki. ".json_encode($tokens));
        }
        $result = (array) $tokens['tokens'];
        $this->tokencache = array_merge($this->tokencache, $result );
        return $result;
    }
680317
protected static function tokenize($string)
    {
        self::init();

        $tokens = array();

        // Used for debugging if there is an error while tokenizing the string
        $original_length = strlen($string);

        // Used to make sure the string keeps shrinking on each iteration
        $old_string_len = strlen($string) + 1;

        $token = null;

        $current_length = strlen($string);

        // Keep processing the string until it is empty
        while ($current_length) {
            // If the string stopped shrinking, there was a problem
            if ($old_string_len <= $current_length) {
                $tokens[] = array(
                    self::TOKEN_VALUE=>$string,
                    self::TOKEN_TYPE=>self::TOKEN_TYPE_ERROR
                );

                return $tokens;
            }
            $old_string_len =  $current_length;

            // Determine if we can use caching
            if ($current_length >= self::$max_cachekey_size) {
                $cacheKey = substr($string,0,self::$max_cachekey_size);
            } else {
                $cacheKey = false;
            }

            // See if the token is already cached
            if ($cacheKey && isset(self::$token_cache[$cacheKey])) {
                // Retrieve from cache
                $token = self::$token_cache[$cacheKey];
                $token_length = strlen($token[self::TOKEN_VALUE]);
                self::$cache_hits++;
            } else {
                // Get the next token and the token type
                $token = self::getNextToken($string, $token);
                $token_length = strlen($token[self::TOKEN_VALUE]);
                self::$cache_misses++;

                // If the token is shorter than the max length, store it in cache
                if ($cacheKey && $token_length < self::$max_cachekey_size) {
                    self::$token_cache[$cacheKey] = $token;
                }
            }

            $tokens[] = $token;

            // Advance the string
            $string = substr($string, $token_length);

            $current_length -= $token_length;
        }

        return $tokens;
    }
406646
public function loadAndDecryptWithKey(string $token, JWK $key, ?int &$recipient): JWE
    {
        $keyset = JWKSet::createFromKeys([$key]);

        return $this->loadAndDecryptWithKeySet($token, $keyset, $recipient);
    }
965350
function getNewChars(key, characterSet) {
  const cachedFontAtlas = cache.get(key);
  if (!cachedFontAtlas) {
    return characterSet;
  }

  const newChars = [];
  const cachedMapping = cachedFontAtlas.mapping;
  let cachedCharSet = Object.keys(cachedMapping);
  cachedCharSet = new Set(cachedCharSet);

  let charSet = characterSet;
  if (charSet instanceof Array) {
    charSet = new Set(charSet);
  }

  charSet.forEach(char => {
    if (!cachedCharSet.has(char)) {
      newChars.push(char);
    }
  });

  return newChars;
}
1288567
private function seekToNextRelevantToken(\Iterator $tokenIterator)
    {
        for (; $tokenIterator->valid(); $tokenIterator->next()) {
            $t = $tokenIterator->current();
            if (T_WHITESPACE !== $t[0]) {
                break;
            }
        }
    }
886447
static function parse_string( $src, $unicode = true, $parser = __CLASS__, $lexer = 'JTokenizer' ){
		$Tokenizer = new $lexer( false, $unicode);
		$tokens = $Tokenizer->get_all_tokens( $src );
		unset( $src );
		$Parser = new $parser;
		return $Parser->parse( $tokens );
	}
592851
public function getTokenString()
    {
        $cacheId = $this->getCacheId();

        if ($this->cache && $data = $this->cache->fetch($cacheId)) {
            return $data['access_token'];
        }

        $response = $this->getTokenResponse();

        if ($this->cache) {
            $this->cache->save($cacheId, $response, $response['expires_in']);
        }

        return $response['access_token'];
    }
830082
private function tokenize($string, $separator = '')
    {
        if (!strcmp($separator, '')) {
            $separator = $string;
            $string = $this->headerNextToken;
        }

        for ($character = 0; $character < strlen($separator); $character++) {
            if (gettype($position = strpos($string, $separator[$character])) == 'integer') {
                $found = (isset($found) ? min($found, $position) : $position);
            }
        }

        if (isset($found)) {
            $this->headerNextToken = substr($string, $found + 1);

            return substr($string, 0, $found);
        } else {
            $this->headerNextToken = '';

            return $string;
        }
    }