OAuthCommonStorageMemory

Stores a token in-memory only (destroyed at end of script execution).

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/Common/Storage/Memory.php  
  1. class Memory implements TokenStorageInterface 
  2. /** 
  3. * @var object|TokenInterface 
  4. */ 
  5. protected $tokens; 
  6.  
  7. /** 
  8. * @var array 
  9. */ 
  10. protected $states; 
  11.  
  12. public function __construct() 
  13. $this->tokens = array(); 
  14. $this->states = array(); 
  15.  
  16. /** 
  17. * {@inheritDoc} 
  18. */ 
  19. public function retrieveAccessToken($service) 
  20. if ($this->hasAccessToken($service)) { 
  21. return $this->tokens[$service]; 
  22.  
  23. throw new TokenNotFoundException('Token not stored'); 
  24.  
  25. /** 
  26. * {@inheritDoc} 
  27. */ 
  28. public function storeAccessToken($service, TokenInterface $token) 
  29. $this->tokens[$service] = $token; 
  30.  
  31. // allow chaining 
  32. return $this; 
  33.  
  34. /** 
  35. * {@inheritDoc} 
  36. */ 
  37. public function hasAccessToken($service) 
  38. return isset($this->tokens[$service]) && $this->tokens[$service] instanceof TokenInterface; 
  39.  
  40. /** 
  41. * {@inheritDoc} 
  42. */ 
  43. public function clearToken($service) 
  44. if (array_key_exists($service, $this->tokens)) { 
  45. unset($this->tokens[$service]); 
  46.  
  47. // allow chaining 
  48. return $this; 
  49.  
  50. /** 
  51. * {@inheritDoc} 
  52. */ 
  53. public function clearAllTokens() 
  54. $this->tokens = array(); 
  55.  
  56. // allow chaining 
  57. return $this; 
  58.  
  59. /** 
  60. * {@inheritDoc} 
  61. */ 
  62. public function retrieveAuthorizationState($service) 
  63. if ($this->hasAuthorizationState($service)) { 
  64. return $this->states[$service]; 
  65.  
  66. throw new AuthorizationStateNotFoundException('State not stored'); 
  67.  
  68. /** 
  69. * {@inheritDoc} 
  70. */ 
  71. public function storeAuthorizationState($service, $state) 
  72. $this->states[$service] = $state; 
  73.  
  74. // allow chaining 
  75. return $this; 
  76.  
  77. /** 
  78. * {@inheritDoc} 
  79. */ 
  80. public function hasAuthorizationState($service) 
  81. return isset($this->states[$service]) && null !== $this->states[$service]; 
  82.  
  83. /** 
  84. * {@inheritDoc} 
  85. */ 
  86. public function clearAuthorizationState($service) 
  87. if (array_key_exists($service, $this->states)) { 
  88. unset($this->states[$service]); 
  89.  
  90. // allow chaining 
  91. return $this; 
  92.  
  93. /** 
  94. * {@inheritDoc} 
  95. */ 
  96. public function clearAllAuthorizationStates() 
  97. $this->states = array(); 
  98.  
  99. // allow chaining 
  100. return $this;