[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/http-foundation/Session/Storage/Handler/ -> MemcacheSessionHandler.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
  13  
  14  /**
  15   * @author Drak <drak@zikula.org>
  16   */
  17  class MemcacheSessionHandler implements \SessionHandlerInterface
  18  {
  19      private $memcache;
  20  
  21      /**
  22       * @var int Time to live in seconds
  23       */
  24      private $ttl;
  25  
  26      /**
  27       * @var string Key prefix for shared environments
  28       */
  29      private $prefix;
  30  
  31      /**
  32       * Constructor.
  33       *
  34       * List of available options:
  35       *  * prefix: The prefix to use for the memcache keys in order to avoid collision
  36       *  * expiretime: The time to live in seconds
  37       *
  38       * @param \Memcache $memcache A \Memcache instance
  39       * @param array     $options  An associative array of Memcache options
  40       *
  41       * @throws \InvalidArgumentException When unsupported options are passed
  42       */
  43      public function __construct(\Memcache $memcache, array $options = array())
  44      {
  45          if ($diff = array_diff(array_keys($options), array('prefix', 'expiretime'))) {
  46              throw new \InvalidArgumentException(sprintf('The following options are not supported "%s"', implode(', ', $diff)));
  47          }
  48  
  49          $this->memcache = $memcache;
  50          $this->ttl = isset($options['expiretime']) ? (int) $options['expiretime'] : 86400;
  51          $this->prefix = isset($options['prefix']) ? $options['prefix'] : 'sf2s';
  52      }
  53  
  54      /**
  55       * {@inheritdoc}
  56       */
  57      public function open($savePath, $sessionName)
  58      {
  59          return true;
  60      }
  61  
  62      /**
  63       * {@inheritdoc}
  64       */
  65      public function close()
  66      {
  67          return true;
  68      }
  69  
  70      /**
  71       * {@inheritdoc}
  72       */
  73      public function read($sessionId)
  74      {
  75          return $this->memcache->get($this->prefix.$sessionId) ?: '';
  76      }
  77  
  78      /**
  79       * {@inheritdoc}
  80       */
  81      public function write($sessionId, $data)
  82      {
  83          return $this->memcache->set($this->prefix.$sessionId, $data, 0, time() + $this->ttl);
  84      }
  85  
  86      /**
  87       * {@inheritdoc}
  88       */
  89      public function destroy($sessionId)
  90      {
  91          $this->memcache->delete($this->prefix.$sessionId);
  92  
  93          return true;
  94      }
  95  
  96      /**
  97       * {@inheritdoc}
  98       */
  99      public function gc($maxlifetime)
 100      {
 101          // not required here because memcache will auto expire the records anyhow.
 102          return true;
 103      }
 104  
 105      /**
 106       * Return a Memcache instance.
 107       *
 108       * @return \Memcache
 109       */
 110      protected function getMemcache()
 111      {
 112          return $this->memcache;
 113      }
 114  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1