Вход Регистрация
Файл: vendor/lusitanian/oauth/src/OAuth/Common/Storage/Memory.php
Строк: 95
<?php
namespace OAuthCommonStorage;

use 
OAuthCommonTokenTokenInterface;
use 
OAuthCommonStorageExceptionTokenNotFoundException;

/*
 * Stores a token in-memory only (destroyed at end of script execution).
 */
class Memory implements TokenStorageInterface
{
    
/**
     * @var object|TokenInterface
     */
    
protected $tokens;

    public function 
__construct()
    {
        
$this->tokens = array();
    }

    
/**
     * @return OAuthCommonTokenTokenInterface
     * @throws TokenNotFoundException
     */
    
public function retrieveAccessToken($service)
    {
        if (
$this->hasAccessToken($service))
        {
            return 
$this->tokens[$service];
        }

        throw new 
TokenNotFoundException('Token not stored');
    }

    
/**
     * @param OAuthCommonTokenTokenInterface $token
     */
    
public function storeAccessToken($serviceTokenInterface $token)
    {
        
$this->tokens[$service] = $token;

        
// allow chaining
        
return $this;
    }

    
/**
    * @return bool
    */
    
public function hasAccessToken($service)
    {
        return isset(
$this->tokens[$service]) &&
               
$this->tokens[$service] instanceOf TokenInterface;
    }

    
/**
     * Delete the user's token. Aka, log out.
     */
    
public function clearToken($service)
    {
        if (
array_key_exists($service$this->tokens)) {
            unset(
$this->tokens[$service]);
        }

        
// allow chaining
        
return $this;
    }

    
/**
     * Delete *ALL* user tokens. Use with care. Most of the time you will likely
     * want to use clearToken() instead.
     */
    
public function clearAllTokens()
    {
        
$this->tokens = array();

        
// allow chaining
        
return $this;
    }
}
Онлайн: 1
Реклама