[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace OAuth\Common\Storage; 4 5 use OAuth\Common\Token\TokenInterface; 6 use OAuth\Common\Storage\Exception\TokenNotFoundException; 7 8 /** 9 * Stores a token in a PHP session. 10 */ 11 class Session implements TokenStorageInterface 12 { 13 /** 14 * @var string 15 */ 16 protected $sessionVariableName; 17 18 /** 19 * @param bool $startSession Whether or not to start the session upon construction. 20 * @param string $sessionVariableName the variable name to use within the _SESSION superglobal 21 */ 22 public function __construct($startSession = true, $sessionVariableName = 'lusitanian_oauth_token') 23 { 24 if ($startSession && !isset($_SESSION)) { 25 session_start(); 26 } 27 28 $this->sessionVariableName = $sessionVariableName; 29 if (!isset($_SESSION[$sessionVariableName])) { 30 $_SESSION[$sessionVariableName] = array(); 31 } 32 } 33 34 /** 35 * {@inheritDoc} 36 */ 37 public function retrieveAccessToken($service) 38 { 39 if ($this->hasAccessToken($service)) { 40 return unserialize($_SESSION[$this->sessionVariableName][$service]); 41 } 42 43 throw new TokenNotFoundException('Token not found in session, are you sure you stored it?'); 44 } 45 46 /** 47 * {@inheritDoc} 48 */ 49 public function storeAccessToken($service, TokenInterface $token) 50 { 51 $serializedToken = serialize($token); 52 53 if (isset($_SESSION[$this->sessionVariableName]) 54 && is_array($_SESSION[$this->sessionVariableName]) 55 ) { 56 $_SESSION[$this->sessionVariableName][$service] = $serializedToken; 57 } else { 58 $_SESSION[$this->sessionVariableName] = array( 59 $service => $serializedToken, 60 ); 61 } 62 63 // allow chaining 64 return $this; 65 } 66 67 /** 68 * {@inheritDoc} 69 */ 70 public function hasAccessToken($service) 71 { 72 return isset($_SESSION[$this->sessionVariableName], $_SESSION[$this->sessionVariableName][$service]); 73 } 74 75 /** 76 * {@inheritDoc} 77 */ 78 public function clearToken($service) 79 { 80 if (array_key_exists($service, $_SESSION[$this->sessionVariableName])) { 81 unset($_SESSION[$this->sessionVariableName][$service]); 82 } 83 84 // allow chaining 85 return $this; 86 } 87 88 /** 89 * {@inheritDoc} 90 */ 91 public function clearAllTokens() 92 { 93 unset($_SESSION[$this->sessionVariableName]); 94 95 // allow chaining 96 return $this; 97 } 98 99 public function __destruct() 100 { 101 session_write_close(); 102 } 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |