[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

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


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