@param array $claims
@param int   $ttl

@return string
13657
public function encode($claims, $ttl = null)
    {
        if (!$this->_key) {
            throw new MisuseException('Jwt key is not set');
        }

        $key = is_string($this->_key) ? $this->_key : $this->_key[0];

        $claims['iat'] = time();
        $claims['exp'] = time() + ($ttl ?: $this->_ttl);

        $header = $this->base64urlEncode(json_encode(['alg' => $this->_alg, 'typ' => 'JWT']));
        $payload = $this->base64urlEncode(json_encode($claims, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
        $signature = $this->base64urlEncode(hash_hmac(strtr($this->_alg, ['HS' => 'sha']), "$header.$payload", $key, true));

        return "$header.$payload.$signature";
    }
804517
public function setClaims($claims)
    {
        $context = $this->_context;

        if ($claims && (!$context->type || !isset($claims[$context->type]))) {
            foreach ($claims as $claim => $value) {
                if (strlen($claim) > 3 && strrpos($claim, '_id', -3) !== false) {
                    $context->type = substr($claim, 0, -3);
                    break;
                }
            }
        }
        $context->claims = $claims;

        return $this;
    }
1088707
public function setClaimsLocales(array $claimsLocales = null)
    {
        ValidationUtility::ensureNullOrArrayOfString('$claimsLocales', $claimsLocales);

        $this->claimsLocales = $claimsLocales;

        return $this;
    }
1048427
public function createToken($user, $ttl = 3600)
    {
        $expires = time() + (int) $ttl;

        $hash = $this->getEncoder()->generateTokenValue(
            get_class($user),
            $user->getUsername(),
            $user->getPassword(),
            $expires
        );

        $token = new Token();
        $token->setHash($hash);
        $token->setExpiresAt(new \DateTime('@' . $expires));

        $this->updateToken($token);

        return $token;
    }
323922
protected function makePayload($subject, array $customClaims = [])
    {
        return $this->manager->getPayloadFactory()->make(
            array_merge($customClaims, ['sub' => $subject])
        );
    }
667512
public static function valueOrFail($filters, $field, $ttl = null)
    {
        $value = static::value($filters, $field, $ttl);
        if ($value === null) {
            throw new NotFoundException(['valueOrFail: `:model` model with `:query` query record is not exists',
                'model' => static::class,
                'query' => json_encode($filters, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        } else {
            return $value;
        }
    }
506058
private function getValidatableClaims()
    {
        $claims = array();

        foreach ($this->claims as $claim) {
            if ($claim instanceof Validatable) {
                $cliams[] = $claim;
            }
        }

        return $claims;
    }
531512
public function save( $var, $val, $ttl = null )
    {
        if( $ttl === null )
            $ttl = $this->_ttl;

        if( apc_store( $this->_prefix . $var, $val, $ttl ) )
            return $val;

        return null;
    }
877912
def update(self, claim, ttl=None, grace=None):
        
        body = {}
        if ttl is not None:
            body["ttl"] = ttl
        if grace is not None:
            body["grace"] = grace
        if not body:
            raise exc.MissingClaimParameters("You must supply a value for "
                    "'ttl' or 'grace' when calling 'update()'")
        uri = "/%s/%s" % (self.uri_base, utils.get_id(claim))
        resp, resp_body = self.api.method_patch(uri, body=body)
815784
public function computeTTL($ttl = null)
    {
        $ttl = $ttl ?: $this->defaultTTL;
        if ($ttl === null) {
            return null;
        }
        return $ttl + rand(0, $this->ttlVariation);
    }
854997
public function putMany(array $values, $ttl = null)
    {
        if ($ttl === null) {
            return $this->putManyForever($values);
        }

        return $this->putManyAlias($values, $ttl);
    }
541550
public static function normalizeExpireAt($ttl)
    {
        self::checkTtlType($ttl);

        if (is_int($ttl)) {
            return time() + $ttl;
        }

        if ($ttl instanceof DateInterval) {
            $now = new DateTimeImmutable;
            return $now->add($ttl)->getTimestamp();
        }

        return null;
    }
532774
protected static function createNew(
        int $ttl,
        TokenOwnerInterface $owner = null,
        Client $client = null,
        array $scopes = null
    ): self {
        if (is_array($scopes)) {
            $scopes = array_map(function ($scope) {
                return (string) $scope;
            }, $scopes);
        }

        $token = new static();

        $token->token = bin2hex(random_bytes(20));
        $token->owner = $owner;
        $token->client = $client;
        $token->scopes = $scopes ?? [];
        $token->expiresAt = $ttl ? (new DateTime('@' . time(), new DateTimeZone('UTC')))->modify("+$ttl seconds") : null;

        return $token;
    }
809051
function set($key,$val,$ttl=0) {
		$fw=Base::instance();
		if (!$this->dsn)
			return TRUE;
		$ndx=$this->prefix.'.'.$key;
		if ($cached=$this->exists($key))
			$ttl=$cached[1];
		$data=$fw->serialize([$val,microtime(TRUE),$ttl]);
		$parts=explode('=',$this->dsn,2);
		switch ($parts[0]) {
			case 'apc':
			case 'apcu':
				return call_user_func($parts[0].'_store',$ndx,$data,$ttl);
			case 'redis':
				return $this->ref->set($ndx,$data,$ttl?['ex'=>$ttl]:[]);
			case 'memcache':
				return memcache_set($this->ref,$ndx,$data,0,$ttl);
			case 'memcached':
				return $this->ref->set($ndx,$data,$ttl);
			case 'wincache':
				return wincache_ucache_set($ndx,$data,$ttl);
			case 'xcache':
				return xcache_set($ndx,$data,$ttl);
			case 'folder':
				return $fw->write($parts[1].
					str_replace(['/','\\'],'',$ndx),$data);
		}
		return FALSE;
	}
929287
public function set($key, $value, $ttl)
    {
        $curlHandler = $this->curlHandler($key . '?ttl=' . $ttl . 's');

        \curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, true);
        \curl_setopt($curlHandler, CURLOPT_POST, true);
        \curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $value);

        $response = \curl_exec($curlHandler);
        \curl_close($curlHandler);
        return $response;
    }
1397
public function createScript($value, ?int $ttl): string
    {
        $macro = var_export($value, true);

        if (strpos($macro, 'stdClass::__set_state') !== false) {
            $macro = preg_replace_callback("/('([^'\\\\]++|''\\.)')|stdClass::__set_state/", $macro, function($match) {
                return empty($match[1]) ? '(object)' : $match[1];
            });
        }

        return $ttl !== null
            ? "<?php return time() < {$ttl} ? {$macro} : false;"
            : "<?php return {$macro};";
    }
856852
public function set($key, $value, $ttl = null)
    {
        return $this->driver->set($key, serialize($value), $ttl);
    }