[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/vendor/symfony/http-kernel/Profiler/ -> MemcachedProfilerStorage.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\HttpKernel\Profiler;
  13  
  14  @trigger_error('The '.__NAMESPACE__.'\MemcachedProfilerStorage class is deprecated since Symfony 2.8 and will be removed in 3.0. Use FileProfilerStorage instead.', E_USER_DEPRECATED);
  15  
  16  /**
  17   * Memcached Profiler Storage.
  18   *
  19   * @author Andrej Hudec <pulzarraider@gmail.com>
  20   *
  21   * @deprecated Deprecated since Symfony 2.8, to be removed in Symfony 3.0.
  22   *             Use {@link FileProfilerStorage} instead.
  23   */
  24  class MemcachedProfilerStorage extends BaseMemcacheProfilerStorage
  25  {
  26      /**
  27       * @var \Memcached
  28       */
  29      private $memcached;
  30  
  31      /**
  32       * Internal convenience method that returns the instance of the Memcached.
  33       *
  34       * @return \Memcached
  35       *
  36       * @throws \RuntimeException
  37       */
  38      protected function getMemcached()
  39      {
  40          if (null === $this->memcached) {
  41              if (!preg_match('#^memcached://(?(?=\[.*\])\[(.*)\]|(.*)):(.*)$#', $this->dsn, $matches)) {
  42                  throw new \RuntimeException(sprintf('Please check your configuration. You are trying to use Memcached with an invalid dsn "%s". The expected format is "memcached://[host]:port".', $this->dsn));
  43              }
  44  
  45              $host = $matches[1] ?: $matches[2];
  46              $port = $matches[3];
  47  
  48              $memcached = new \Memcached();
  49  
  50              // disable compression to allow appending
  51              $memcached->setOption(\Memcached::OPT_COMPRESSION, false);
  52  
  53              $memcached->addServer($host, $port);
  54  
  55              $this->memcached = $memcached;
  56          }
  57  
  58          return $this->memcached;
  59      }
  60  
  61      /**
  62       * Set instance of the Memcached.
  63       *
  64       * @param \Memcached $memcached
  65       */
  66      public function setMemcached($memcached)
  67      {
  68          $this->memcached = $memcached;
  69      }
  70  
  71      /**
  72       * {@inheritdoc}
  73       */
  74      protected function getValue($key)
  75      {
  76          return $this->getMemcached()->get($key);
  77      }
  78  
  79      /**
  80       * {@inheritdoc}
  81       */
  82      protected function setValue($key, $value, $expiration = 0)
  83      {
  84          return $this->getMemcached()->set($key, $value, time() + $expiration);
  85      }
  86  
  87      /**
  88       * {@inheritdoc}
  89       */
  90      protected function delete($key)
  91      {
  92          return $this->getMemcached()->delete($key);
  93      }
  94  
  95      /**
  96       * {@inheritdoc}
  97       */
  98      protected function appendValue($key, $value, $expiration = 0)
  99      {
 100          $memcached = $this->getMemcached();
 101  
 102          if (!$result = $memcached->append($key, $value)) {
 103              return $memcached->set($key, $value, $expiration);
 104          }
 105  
 106          return $result;
 107      }
 108  }


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