Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

SymfonySession.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 4.78 KiB


001  <?php
002   
003  namespace OAuth\Common\Storage;
004   
005  use OAuth\Common\Token\TokenInterface;
006  use OAuth\Common\Storage\Exception\TokenNotFoundException;
007  use OAuth\Common\Storage\Exception\AuthorizationStateNotFoundException;
008  use Symfony\Component\HttpFoundation\Session\SessionInterface;
009   
010  class SymfonySession implements TokenStorageInterface
011  {
012      private $session;
013      private $sessionVariableName;
014      private $stateVariableName;
015   
016      /**
017       * @param SessionInterface $session
018       * @param bool $startSession
019       * @param string $sessionVariableName
020       * @param string $stateVariableName
021       */
022      public function __construct(
023          SessionInterface $session,
024          $startSession = true,
025          $sessionVariableName = 'lusitanian_oauth_token',
026          $stateVariableName = 'lusitanian_oauth_state'
027      ) {
028          $this->session = $session;
029          $this->sessionVariableName = $sessionVariableName;
030          $this->stateVariableName = $stateVariableName;
031      }
032   
033      /**
034       * {@inheritDoc}
035       */
036      public function retrieveAccessToken($service)
037      {
038          if ($this->hasAccessToken($service)) {
039              // get from session
040              $tokens = $this->session->get($this->sessionVariableName);
041   
042              // one item
043              return $tokens[$service];
044          }
045   
046          throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
047      }
048   
049      /**
050       * {@inheritDoc}
051       */
052      public function storeAccessToken($service, TokenInterface $token)
053      {
054          // get previously saved tokens
055          $tokens = $this->session->get($this->sessionVariableName);
056   
057          if (!is_array($tokens)) {
058              $tokens = array();
059          }
060   
061          $tokens[$service] = $token;
062   
063          // save
064          $this->session->set($this->sessionVariableName, $tokens);
065   
066          // allow chaining
067          return $this;
068      }
069   
070      /**
071       * {@inheritDoc}
072       */
073      public function hasAccessToken($service)
074      {
075          // get from session
076          $tokens = $this->session->get($this->sessionVariableName);
077   
078          return is_array($tokens)
079              && isset($tokens[$service])
080              && $tokens[$service] instanceof TokenInterface;
081      }
082   
083      /**
084       * {@inheritDoc}
085       */
086      public function clearToken($service)
087      {
088          // get previously saved tokens
089          $tokens = $this->session->get($this->sessionVariableName);
090   
091          if (is_array($tokens) && array_key_exists($service, $tokens)) {
092              unset($tokens[$service]);
093   
094              // Replace the stored tokens array
095              $this->session->set($this->sessionVariableName, $tokens);
096          }
097   
098          // allow chaining
099          return $this;
100      }
101   
102      /**
103       * {@inheritDoc}
104       */
105      public function clearAllTokens()
106      {
107          $this->session->remove($this->sessionVariableName);
108   
109          // allow chaining
110          return $this;
111      }
112   
113      /**
114       * {@inheritDoc}
115       */
116      public function retrieveAuthorizationState($service)
117      {
118          if ($this->hasAuthorizationState($service)) {
119              // get from session
120              $states = $this->session->get($this->stateVariableName);
121   
122              // one item
123              return $states[$service];
124          }
125   
126          throw new AuthorizationStateNotFoundException('State not found in session, are you sure you stored it?');
127      }
128   
129      /**
130       * {@inheritDoc}
131       */
132      public function storeAuthorizationState($service, $state)
133      {
134          // get previously saved tokens
135          $states = $this->session->get($this->stateVariableName);
136   
137          if (!is_array($states)) {
138              $states = array();
139          }
140   
141          $states[$service] = $state;
142   
143          // save
144          $this->session->set($this->stateVariableName, $states);
145   
146          // allow chaining
147          return $this;
148      }
149   
150      /**
151       * {@inheritDoc}
152       */
153      public function hasAuthorizationState($service)
154      {
155          // get from session
156          $states = $this->session->get($this->stateVariableName);
157   
158          return is_array($states)
159          && isset($states[$service])
160          && null !== $states[$service];
161      }
162   
163      /**
164       * {@inheritDoc}
165       */
166      public function clearAuthorizationState($service)
167      {
168          // get previously saved tokens
169          $states = $this->session->get($this->stateVariableName);
170   
171          if (is_array($states) && array_key_exists($service, $states)) {
172              unset($states[$service]);
173   
174              // Replace the stored tokens array
175              $this->session->set($this->stateVariableName, $states);
176          }
177   
178          // allow chaining
179          return $this;
180      }
181   
182      /**
183       * {@inheritDoc}
184       */
185      public function clearAllAuthorizationStates()
186      {
187          $this->session->remove($this->stateVariableName);
188   
189          // allow chaining
190          return $this;
191      }
192   
193      /**
194       * @return Session
195       */
196      public function getSession()
197      {
198          return $this->session;
199      }
200  }
201