0

Final Class Yiisoft\Yii\AuthClient\OAuthToken

InheritanceYiisoft\Yii\AuthClient\OAuthToken

Token represents OAuth token.

Protected Methods

Hide inherited methods

Method Description Defined By
defaultExpireDurationParamKey() Fetches default expire duration param key. Yiisoft\Yii\AuthClient\OAuthToken

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( )

                public function __construct()
{
    $this->createTimestamp = time();
}

            
defaultExpireDurationParamKey() protected method

Fetches default expire duration param key.

protected string defaultExpireDurationParamKey ( )
return string

Expire duration param key.

                protected function defaultExpireDurationParamKey(): string
{
    $expireDurationParamKey = 'expires_in';
    /**
     * @var mixed $value
     */
    foreach ($this->getParams() as $name => $value) {
        if (!str_contains((string) $name, 'expir')) {
        } else {
            /** @var string $name */
            $expireDurationParamKey = $name;
            break;
        }
    }
    return $expireDurationParamKey;
}

            
getExpireDuration() public method

Returns the token expiration duration.

return mixed token expiration duration.

public mixed getExpireDuration ( )

                public function getExpireDuration(): mixed
{
    return $this->getParam($this->getExpireDurationParamKey());
}

            
getExpireDurationParamKey() public method

public string getExpireDurationParamKey ( )
return string

Expire duration param key.

                public function getExpireDurationParamKey(): string
{
    if ($this->expireDurationParamKey === null) {
        $this->expireDurationParamKey = $this->defaultExpireDurationParamKey();
    }
    return $this->expireDurationParamKey;
}

            
getIsExpired() public method

Checks if token has expired.

public boolean getIsExpired ( )
return boolean

Is token expired.

                public function getIsExpired(): bool
{
    $expirationDuration = (int) $this->getExpireDuration();
    return time() >= ($this->createTimestamp + $expirationDuration);
}

            
getIsValid() public method

Checks if token is valid.

public boolean getIsValid ( )
return boolean

Is token valid.

                public function getIsValid(): bool
{
    $token = $this->getToken();
    return strlen($token ?? '') > 0 && !$this->getIsExpired();
}

            
getParam() public method

Returns param by name.

public mixed getParam ( string $name )
$name string

Param name.

return mixed

Param value.

                public function getParam(string $name): mixed
{
    return $this->params[$name] ?? null;
}

            
getParams() public method

public array getParams ( )

                public function getParams(): array
{
    return $this->params;
}

            
getToken() public method

Returns token value.

public ?string getToken ( )

                public function getToken(): ?string
{
    /** @var string|null */
    return $this->getParam($this->tokenParamKey);
}

            
getTokenSecret() public method

Returns the token secret value.

public string getTokenSecret ( )
return string

Token secret value.

                public function getTokenSecret(): string
{
    /** @var string */
    return $this->getParam($this->tokenSecretParamKey ?: 'oauth_token_secret');
}

            
setExpireDuration() public method

Sets token expire duration.

public void setExpireDuration ( integer $expireDuration )
$expireDuration integer

Token expiration duration.

                public function setExpireDuration(int $expireDuration): void
{
    $this->setParam($this->getExpireDurationParamKey(), $expireDuration);
}

            
setParam() public method

Sets param by name.

public void setParam ( string $name, mixed $value )
$name string

Param name.

$value mixed

Param value,

                public function setParam(string $name, mixed $value): void
{
    $this->params[$name] = $value;
}

            
setParams() public method

public void setParams ( array $params )
$params array

                public function setParams(array $params): void
{
    $this->params = $params;
}

            
setToken() public method

Sets token value.

public void setToken ( string $token )
$token string

Token value.

                public function setToken(string $token): void
{
    $this->setParam($this->tokenParamKey ?: 'oauth_token', $token);
}

            
setTokenParamKey() public method

Sets the name of the {@see params} key, which stores the token value.

public void setTokenParamKey ( string $tokenParamKey )
$tokenParamKey string

Token param key.

                public function setTokenParamKey(string $tokenParamKey): void
{
    $this->tokenParamKey = $tokenParamKey;
}

            
setTokenSecret() public method

Sets the token secret value.

public void setTokenSecret ( string $tokenSecret )
$tokenSecret string

Token secret.

                public function setTokenSecret(string $tokenSecret): void
{
    $this->setParam($this->tokenSecretParamKey ?: 'oauth_token_secret', $tokenSecret);
}