Class yii\authclient\OAuthToken

Inheritanceyii\authclient\OAuthToken » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/OAuthToken.php

Token represents OAuth token.

Public Methods

Hide inherited methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() yii\authclient\OAuthToken
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
getExpireDuration() Returns the token expiration duration. yii\authclient\OAuthToken
getExpireDurationParamKey() yii\authclient\OAuthToken
getIsExpired() Checks if token has expired. yii\authclient\OAuthToken
getIsValid() Checks if token is valid. yii\authclient\OAuthToken
getParam() Returns param by name. yii\authclient\OAuthToken
getParams() yii\authclient\OAuthToken
getToken() Returns token value. yii\authclient\OAuthToken
getTokenSecret() Returns the token secret value. yii\authclient\OAuthToken
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\authclient\OAuthToken
setExpireDuration() Sets token expire duration. yii\authclient\OAuthToken
setExpireDurationParamKey() yii\authclient\OAuthToken
setParam() Sets param by name. yii\authclient\OAuthToken
setParams() yii\authclient\OAuthToken
setToken() Sets token value. yii\authclient\OAuthToken
setTokenSecret() Sets the token secret value. yii\authclient\OAuthToken

Protected Methods

Hide inherited methods

Method Description Defined By
defaultExpireDurationParamKey() Fetches default expire duration param key. yii\authclient\OAuthToken

Property Details

Hide inherited properties

$createTimestamp public property

Object creation timestamp.

public integer $createTimestamp null
$expireDuration public property

Token expiration duration. Note that the type of this property differs in getter and setter. See getExpireDuration() and setExpireDuration() for details.

public integer $expireDuration null
$expireDurationParamKey public property

Expire duration param key.

$isExpired public property

Is token expired.

public boolean $isExpired null
$isValid public property

Is token valid.

public boolean $isValid null
$params public property
public array $params null
$token public property

Token value.

public string $token null
$tokenParamKey public property

Key in $params array, which stores token key.

public string $tokenParamKey 'oauth_token'
$tokenSecret public property

Token secret value.

public string $tokenSecret null
$tokenSecretParamKey public property

Key in $params array, which stores token secret key.

public string $tokenSecretParamKey 'oauth_token_secret'

Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name string

The method name

$params array

Method parameters

return mixed

The method return value

throws yii\base\UnknownMethodException

when calling unknown method

                public function __call($name, $params)
{
    throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}

            
__construct() public method

public void __construct ( array $config = [] )
$config

                public function __construct(array $config = [])
{
    if (array_key_exists('tokenParamKey', $config)) {
        $this->tokenParamKey = ArrayHelper::remove($config, 'tokenParamKey');
    }
    if (array_key_exists('tokenSecretParamKey', $config)) {
        $this->tokenSecretParamKey = ArrayHelper::remove($config, 'tokenSecretParamKey');
    }
    parent::__construct($config);
}

            
__get() public method

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;.

See also __set().

public mixed __get ( $name )
$name string

The property name

return mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is write-only

                public function __get($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter();
    } elseif (method_exists($this, 'set' . $name)) {
        throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
    }
    throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}

            
__isset() public method

Defined in: yii\base\BaseObject::__isset()

Checks if a property is set, i.e. defined and not null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($object->property).

Note that if the property is not defined, false will be returned.

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name string

The property name or the event name

return boolean

Whether the named property is set (not null).

                public function __isset($name)
{
    $getter = 'get' . $name;
    if (method_exists($this, $getter)) {
        return $this->$getter() !== null;
    }
    return false;
}

            
__set() public method

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;.

See also __get().

public void __set ( $name, $value )
$name string

The property name or the event name

$value mixed

The property value

throws yii\base\UnknownPropertyException

if the property is not defined

throws yii\base\InvalidCallException

if the property is read-only

                public function __set($name, $value)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter($value);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
    } else {
        throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
    }
}

            
__unset() public method

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property).

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name string

The property name

throws yii\base\InvalidCallException

if the property is read only.

                public function __unset($name)
{
    $setter = 'set' . $name;
    if (method_exists($this, $setter)) {
        $this->$setter(null);
    } elseif (method_exists($this, 'get' . $name)) {
        throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
    }
}

            
canGetProperty() public method

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be read

                public function canGetProperty($name, $checkVars = true)
{
    return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}

            
canSetProperty() public method

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property can be written

                public function canSetProperty($name, $checkVars = true)
{
    return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}

            
className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use ::class instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return string

The fully qualified name of this class.

                public static function className()
{
    return get_called_class();
}

            
defaultExpireDurationParamKey() protected method

Fetches default expire duration param key.

protected string defaultExpireDurationParamKey ( )
return string

Expire duration param key.

                protected function defaultExpireDurationParamKey()
{
    $expireDurationParamKey = 'expires_in';
    foreach ($this->getParams() as $name => $value) {
        if (strpos($name, 'expir') !== false) {
            $expireDurationParamKey = $name;
            break;
        }
    }
    return $expireDurationParamKey;
}

            
getExpireDuration() public method

Returns the token expiration duration.

public integer getExpireDuration ( )
return integer

Token expiration duration.

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

            
getExpireDurationParamKey() public method

public string getExpireDurationParamKey ( )
return string

Expire duration param key.

                public function getExpireDurationParamKey()
{
    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()
{
    $expirationDuration = $this->getExpireDuration();
    if (empty($expirationDuration)) {
        return false;
    }
    return (time() >= ($this->createTimestamp + $expirationDuration));
}

            
getIsValid() public method

Checks if token is valid.

public boolean getIsValid ( )
return boolean

Is token valid.

                public function getIsValid()
{
    $token = $this->getToken();
    return (!empty($token) && !$this->getIsExpired());
}

            
getParam() public method

Returns param by name.

public mixed getParam ( $name )
$name string

Param name.

return mixed

Param value.

                public function getParam($name)
{
    return isset($this->_params[$name]) ? $this->_params[$name] : null;
}

            
getParams() public method

public array getParams ( )

                public function getParams()
{
    return $this->_params;
}

            
getToken() public method

Returns token value.

public string getToken ( )
return string

Token value.

                public function getToken()
{
    return $this->getParam($this->tokenParamKey);
}

            
getTokenSecret() public method

Returns the token secret value.

public string getTokenSecret ( )
return string

Token secret value.

                public function getTokenSecret()
{
    return $this->getParam($this->tokenSecretParamKey);
}

            
hasMethod() public method

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function method_exists(). You may override this method when you implemented the php magic method __call().

public boolean hasMethod ( $name )
$name string

The method name

return boolean

Whether the method is defined

                public function hasMethod($name)
{
    return method_exists($this, $name);
}

            
hasProperty() public method

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);

See also:

public boolean hasProperty ( $name, $checkVars true )
$name string

The property name

$checkVars boolean

Whether to treat member variables as properties

return boolean

Whether the property is defined

                public function hasProperty($name, $checkVars = true)
{
    return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}

            
init() public method

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

                public function init()
{
    if ($this->createTimestamp === null) {
        $this->createTimestamp = time();
    }
}

            
setExpireDuration() public method

Sets token expire duration.

public void setExpireDuration ( $expireDuration )
$expireDuration string

Token expiration duration.

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

            
setExpireDurationParamKey() public method

public void setExpireDurationParamKey ( $expireDurationParamKey )
$expireDurationParamKey string

Expire duration param key.

                public function setExpireDurationParamKey($expireDurationParamKey)
{
    $this->_expireDurationParamKey = $expireDurationParamKey;
}

            
setParam() public method

Sets param by name.

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

Param name.

$value mixed

Param value,

                public function setParam($name, $value)
{
    $this->_params[$name] = $value;
}

            
setParams() public method

public void setParams ( array $params )
$params array

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

            
setToken() public method

Sets token value.

public $this setToken ( $token )
$token string

Token value.

return $this

The object itself

                public function setToken($token)
{
    $this->setParam($this->tokenParamKey, $token);
}

            
setTokenSecret() public method

Sets the token secret value.

public void setTokenSecret ( $tokenSecret )
$tokenSecret string

Token secret.

                public function setTokenSecret($tokenSecret)
{
    $this->setParam($this->tokenSecretParamKey, $tokenSecret);
}