Class yii\authclient\OAuthToken
| Inheritance | yii\ |
|---|---|
| Implements | yii\ |
| Available since version | 2.0 |
| Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/OAuthToken.php |
Token represents OAuth token.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $createTimestamp | integer | Object creation timestamp. | yii\ |
| $expireDuration | string | Token expiration duration. | yii\ |
| $expireDurationParamKey | string | Expire duration param key. | yii\ |
| $isExpired | boolean | Is token expired. | yii\ |
| $isValid | boolean | Is token valid. | yii\ |
| $params | array | yii\ |
|
| $refreshToken | string | yii\ |
|
| $refreshTokenParamKey | string | Key in $params array, which stores refresh token key. | yii\ |
| $token | string | Token value. | yii\ |
| $tokenParamKey | string | Key in $params array, which stores token key. | yii\ |
| $tokenSecret | string | Token secret value. | yii\ |
| $tokenSecretParamKey | string | Key in $params array, which stores token secret key. | yii\ |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| defaultExpireDurationParamKey() | Fetches default expire duration param key. | yii\ |
Property Details
Expire duration param key.
Key in $params array, which stores refresh token key.
Key in $params array, which stores token key.
Key in $params array, which stores token secret key.
Method Details
Defined in:
yii\
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 __call( string $name, array $params ): mixed | ||
| $name | string |
The method name |
| $params | array |
Method parameters |
| return | mixed |
The method return value |
|---|---|---|
| throws | yii\ |
when calling unknown method |
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
| public __construct( array $config = [] ): mixed | ||
| $config | array | |
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');
}
if (array_key_exists('refreshTokenParamKey', $config)) {
$this->refreshTokenParamKey = ArrayHelper::remove($config, 'refreshTokenParamKey');
}
parent::__construct($config);
}
Defined in:
yii\
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 __get( string $name ): mixed | ||
| $name | string |
The property name |
| return | mixed |
The property value |
|---|---|---|
| throws | yii\ |
if the property is not defined |
| throws | yii\ |
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);
}
Defined in:
yii\
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.
| public __isset( string $name ): boolean | ||
| $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;
}
Defined in:
yii\
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 __set( string $name, mixed $value ): mixed | ||
| $name | string |
The property name or the event name |
| $value | mixed |
The property value |
| throws | yii\ |
if the property is not defined |
|---|---|---|
| throws | yii\ |
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);
}
}
Defined in:
yii\
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.
| public __unset( string $name ): mixed | ||
| $name | string |
The property name |
| throws | yii\ |
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);
}
}
Defined in:
yii\
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
$checkVarsis true);
See also canSetProperty().
| public canGetProperty( string $name, boolean $checkVars = true ): boolean | ||
| $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);
}
Defined in:
yii\
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
$checkVarsis true);
See also canGetProperty().
| public canSetProperty( string $name, boolean $checkVars = true ): boolean | ||
| $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);
}
::class instead.
Defined in:
yii\
Returns the fully qualified name of this class.
| public static className( ): string | ||
| return | string |
The fully qualified name of this class. |
|---|---|---|
public static function className()
{
return get_called_class();
}
Fetches default expire duration param key.
| protected defaultExpireDurationParamKey( ): string | ||
| 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;
}
Returns the token expiration duration.
| public getExpireDuration( ): integer | ||
| return | integer |
Token expiration duration. |
|---|---|---|
public function getExpireDuration()
{
return $this->getParam($this->getExpireDurationParamKey());
}
| public getExpireDurationParamKey( ): string | ||
| return | string |
Expire duration param key. |
|---|---|---|
public function getExpireDurationParamKey()
{
if ($this->_expireDurationParamKey === null) {
$this->_expireDurationParamKey = $this->defaultExpireDurationParamKey();
}
return $this->_expireDurationParamKey;
}
Checks if token has expired.
| public getIsExpired( ): boolean | ||
| return | boolean |
Is token expired. |
|---|---|---|
public function getIsExpired()
{
$expirationDuration = $this->getExpireDuration();
if (empty($expirationDuration)) {
return false;
}
return (time() >= ($this->createTimestamp + $expirationDuration));
}
Checks if token is valid.
| public getIsValid( ): boolean | ||
| return | boolean |
Is token valid. |
|---|---|---|
public function getIsValid()
{
$token = $this->getToken();
return (!empty($token) && !$this->getIsExpired());
}
Returns param by name.
| public getParam( string $name ): mixed | ||
| $name | string |
Param name. |
| return | mixed |
Param value. |
|---|---|---|
public function getParam($name)
{
return isset($this->_params[$name]) ? $this->_params[$name] : null;
}
| public getRefreshToken( ): mixed |
public function getRefreshToken()
{
return $this->getParam($this->refreshTokenParamKey);
}
Returns token value.
| public getToken( ): string | ||
| return | string |
Token value. |
|---|---|---|
public function getToken()
{
return $this->getParam($this->tokenParamKey);
}
Returns the token secret value.
| public getTokenSecret( ): string | ||
| return | string |
Token secret value. |
|---|---|---|
public function getTokenSecret()
{
return $this->getParam($this->tokenSecretParamKey);
}
Defined in:
yii\
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 hasMethod( string $name ): boolean | ||
| $name | string |
The method name |
| return | boolean |
Whether the method is defined |
|---|---|---|
public function hasMethod($name)
{
return method_exists($this, $name);
}
Defined in:
yii\
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
$checkVarsis true);
See also:
| public hasProperty( string $name, boolean $checkVars = true ): boolean | ||
| $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);
}
| public hasRefreshToken( ): mixed |
public function hasRefreshToken()
{
return !!$this->getRefreshToken();
}
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
| public init( ): mixed |
public function init()
{
if ($this->createTimestamp === null) {
$this->createTimestamp = time();
}
}
Sets token expire duration.
| public setExpireDuration( string $expireDuration ): mixed | ||
| $expireDuration | string |
Token expiration duration. |
public function setExpireDuration($expireDuration)
{
$this->setParam($this->getExpireDurationParamKey(), $expireDuration);
}
| public setExpireDurationParamKey( string $expireDurationParamKey ): mixed | ||
| $expireDurationParamKey | string |
Expire duration param key. |
public function setExpireDurationParamKey($expireDurationParamKey)
{
$this->_expireDurationParamKey = $expireDurationParamKey;
}
Sets param by name.
| public setParam( string $name, mixed $value ): mixed | ||
| $name | string |
Param name. |
| $value | mixed |
Param value, |
public function setParam($name, $value)
{
$this->_params[$name] = $value;
}
| public setParams( array $params ): mixed | ||
| $params | array | |
public function setParams(array $params)
{
$this->_params = $params;
}
Sets refresh token.
| public setRefreshToken( string $refreshToken ): mixed | ||
| $refreshToken | string | |
public function setRefreshToken($refreshToken)
{
$this->setParam($this->refreshTokenParamKey, $refreshToken);
}
Sets token value.
| public setToken( string $token ): $this | ||
| $token | string |
Token value. |
| return | $this |
The object itself |
|---|---|---|
public function setToken($token)
{
$this->setParam($this->tokenParamKey, $token);
}
Sets the token secret value.
| public setTokenSecret( string $tokenSecret ): mixed | ||
| $tokenSecret | string |
Token secret. |
public function setTokenSecret($tokenSecret)
{
$this->setParam($this->tokenSecretParamKey, $tokenSecret);
}