Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Session.php
001 <?php
002 namespace OAuth\Common\Storage;
003
004 use OAuth\Common\Token\TokenInterface;
005 use OAuth\Common\Storage\Exception\TokenNotFoundException;
006
007 /**
008 * Stores a token in a PHP session.
009 */
010 class Session implements TokenStorageInterface
011 {
012 /**
013 * @var string
014 */
015 protected $sessionVariableName;
016
017 /**
018 * @param bool $startSession Whether or not to start the session upon construction.
019 * @param string $sessionVariableName the variable name to use within the _SESSION superglobal
020 */
021 public function __construct($startSession = true, $sessionVariableName = 'lusitanian_oauth_token')
022 {
023 if( $startSession && !isset($_SESSION)) {
024 session_start();
025 }
026
027 $this->sessionVariableName = $sessionVariableName;
028 if (!isset($_SESSION[$sessionVariableName]))
029 {
030 $_SESSION[$sessionVariableName] = array();
031 }
032 }
033
034 /**
035 * @return \OAuth\Common\Token\TokenInterface
036 * @throws TokenNotFoundException
037 */
038 public function retrieveAccessToken($service)
039 {
040 if ($this->hasAccessToken($service))
041 {
042 return $_SESSION[$this->sessionVariableName][$service];
043 }
044
045 throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
046 }
047
048 /**
049 * @param \OAuth\Common\Token\TokenInterface $token
050 */
051 public function storeAccessToken($service, TokenInterface $token)
052 {
053 if (isset($_SESSION[$this->sessionVariableName]) &&
054 is_array($_SESSION[$this->sessionVariableName]))
055 {
056 $_SESSION[$this->sessionVariableName][$service] = $token;
057 }
058 else
059 {
060 $_SESSION[$this->sessionVariableName] = array(
061 $service => $token,
062 );
063 }
064
065 // allow chaining
066 return $this;
067 }
068
069 /**
070 * @return bool
071 */
072 public function hasAccessToken($service)
073 {
074 return isset($_SESSION[$this->sessionVariableName], $_SESSION[$this->sessionVariableName][$service]);
075 }
076
077 /**
078 * Delete the user's token. Aka, log out.
079 */
080 public function clearToken($service)
081 {
082 if (array_key_exists($service, $_SESSION[$this->sessionVariableName])) {
083 unset($_SESSION[$this->sessionVariableName][$service]);
084 }
085
086 // allow chaining
087 return $this;
088 }
089
090 /**
091 * Delete *ALL* user tokens. Use with care. Most of the time you will likely
092 * want to use clearToken() instead.
093 */
094 public function clearAllTokens()
095 {
096 unset($_SESSION[$this->sessionVariableName]);
097
098 // allow chaining
099 return $this;
100 }
101
102 public function __destruct()
103 {
104 session_write_close();
105 }
106 }
107