[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/lusitanian/oauth/src/OAuth/Common/Storage/ -> SymfonySession.php (source)

   1  <?php
   2  
   3  namespace OAuth\Common\Storage;
   4  
   5  use OAuth\Common\Token\TokenInterface;
   6  use OAuth\Common\Storage\Exception\TokenNotFoundException;
   7  use Symfony\Component\HttpFoundation\Session\SessionInterface;
   8  
   9  class SymfonySession implements TokenStorageInterface
  10  {
  11      private $session;
  12      private $sessionVariableName;
  13  
  14      public function __construct(
  15          SessionInterface $session,
  16          $startSession = true,
  17          $sessionVariableName = 'lusitanian_oauth_token'
  18      ) {
  19          $this->session = $session;
  20          $this->sessionVariableName = $sessionVariableName;
  21      }
  22  
  23      /**
  24       * {@inheritDoc}
  25       */
  26      public function retrieveAccessToken($service)
  27      {
  28          if ($this->hasAccessToken($service)) {
  29              // get from session
  30              $tokens = $this->session->get($this->sessionVariableName);
  31  
  32              // one item
  33              return $tokens[$service];
  34          }
  35  
  36          throw new TokenNotFoundException('Token not found in session, are you sure you stored it?');
  37      }
  38  
  39      /**
  40       * {@inheritDoc}
  41       */
  42      public function storeAccessToken($service, TokenInterface $token)
  43      {
  44          // get previously saved tokens
  45          $tokens = $this->session->get($this->sessionVariableName);
  46  
  47          if (!is_array($tokens)) {
  48              $tokens = array();
  49          }
  50  
  51          $tokens[$service] = $token;
  52  
  53          // save
  54          $this->session->set($this->sessionVariableName, $tokens);
  55  
  56          // allow chaining
  57          return $this;
  58      }
  59  
  60      /**
  61       * {@inheritDoc}
  62       */
  63      public function hasAccessToken($service)
  64      {
  65          // get from session
  66          $tokens = $this->session->get($this->sessionVariableName);
  67  
  68          return is_array($tokens)
  69              && isset($tokens[$service])
  70              && $tokens[$service] instanceof TokenInterface;
  71      }
  72  
  73      /**
  74       * {@inheritDoc}
  75       */
  76      public function clearToken($service)
  77      {
  78          // get previously saved tokens
  79          $tokens = $this->session->get($this->sessionVariableName);
  80  
  81          if (is_array($tokens) && array_key_exists($service, $tokens)) {
  82              unset($tokens[$service]);
  83  
  84              // Replace the stored tokens array
  85              $this->session->set($this->sessionVariableName, $tokens);
  86          }
  87  
  88          // allow chaining
  89          return $this;
  90      }
  91  
  92      /**
  93       * {@inheritDoc}
  94       */
  95      public function clearAllTokens()
  96      {
  97          $this->session->remove($this->sessionVariableName);
  98  
  99          // allow chaining
 100          return $this;
 101      }
 102  
 103      /**
 104       * @return Session
 105       */
 106      public function getSession()
 107      {
 108          return $this->session;
 109      }
 110  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1