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.
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:58 - Dateigröße: 2.92 KiB


 001  <?php
 002  namespace OAuth\Common\Storage;
 003   
 004  use OAuth\Common\Token\TokenInterface;
 005  use OAuth\Common\Storage\Exception\TokenNotFoundException;
 006  use Symfony\Component\HttpFoundation\Session\SessionInterface;
 007   
 008  class SymfonySession implements TokenStorageInterface
 009  {
 010      private $session;
 011      private $sessionVariableName;
 012   
 013      public function __construct(SessionInterface $session, $startSession = true, $sessionVariableName = 'lusitanian_oauth_token')
 014      {
 015          $this->session = $session;
 016          $this->sessionVariableName = $sessionVariableName;
 017   
 018          if (!$this->session->has($sessionVariableName))
 019          {
 020              $this->session->set($sessionVariableName, array());
 021          }
 022      }
 023   
 024      /**
 025       * @return \OAuth\Common\Token\TokenInterface
 026       * @throws TokenNotFoundException
 027       */
 028      public function retrieveAccessToken($service)
 029      {
 030          if ($this->hasAccessToken($service)) {
 031              // get from session
 032              $tokens = $this->session->get($this->sessionVariableName);
 033   
 034              // one item
 035              return $tokens[$service];
 036          }
 037   
 038          throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
 039      }
 040   
 041      public function storeAccessToken($service, TokenInterface $token)
 042      {
 043          // get previously saved tokens
 044          $tokens = $this->session->get($this->sessionVariableName);
 045   
 046          if (is_array($tokens))
 047          {
 048              // add to array
 049              $tokens[$service] = $token;
 050          }
 051          else
 052          {
 053              // new array
 054              $tokens = array(
 055                  $service => $token,
 056              );
 057          }
 058   
 059          // save
 060          $this->session->set($this->sessionVariableName, $tokens);
 061   
 062          // allow chaining
 063          return $this;
 064      }
 065   
 066      /**
 067      * @return bool
 068      */
 069      public function hasAccessToken($service)
 070      {
 071          // get from session
 072          $tokens = $this->session->get($this->sessionVariableName);
 073   
 074          return is_array($tokens) &&
 075                 isset($tokens[$service]) &&
 076                 $tokens[$service] instanceof TokenInterface;
 077      }
 078   
 079      /**
 080       * Delete the user's token. Aka, log out.
 081       */
 082      public function clearToken($service)
 083      {
 084          // get previously saved tokens
 085          $tokens = $this->session->get($this->sessionVariableName);
 086   
 087          if (array_key_exists($service, $tokens)) {
 088              unset($tokens[$service]);
 089          }
 090   
 091          // Replace the stored tokens array
 092          $this->session->set($this->sessionVariableName, $tokens);
 093   
 094          // allow chaining
 095          return $this;
 096      }
 097   
 098      /**
 099       * Delete *ALL* user tokens. Use with care. Most of the time you will likely
 100       * want to use clearToken() instead.
 101       */
 102      public function clearAllTokens()
 103      {
 104          $this->session->remove($this->sessionVariableName);
 105   
 106          // allow chaining
 107          return $this;
 108      }
 109   
 110      /**
 111       * @return Session
 112       */
 113      public function getSession()
 114      {
 115          return $this->session;
 116      }
 117  }
 118