Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / memcache / src / DrupalMemcache.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\memcache\DrupalMemcache.
6  */
7
8 namespace Drupal\memcache;
9
10 use Psr\Log\LogLevel;
11
12 /**
13  * Class DrupalMemcache.
14  */
15 class DrupalMemcache extends DrupalMemcacheBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function __construct(DrupalMemcacheConfig $settings) {
21     parent::__construct($settings);
22
23     $this->memcache = new \Memcache();
24   }
25
26   /**
27    * @{@inheritdoc}
28    */
29   public function addServer($server_path, $persistent = FALSE) {
30     list($host, $port) = explode(':', $server_path);
31
32     // Support unix sockets in the format 'unix:///path/to/socket'.
33     if ($host == 'unix') {
34       // When using unix sockets with Memcache use the full path for $host.
35       $host = $server_path;
36       // Port is always 0 for unix sockets.
37       $port = 0;
38     }
39
40     // When using the PECL memcache extension, we must use ->(p)connect
41     // for the first connection.
42     return $this->connect($host, $port, $persistent);
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function close() {
49     $this->memcache->close();
50   }
51
52   /**
53    * Connects to a memcache server.
54    *
55    * @param string $host
56    * @param int $port
57    * @param bool $persistent
58    *
59    * @return bool|mixed
60    */
61   protected function connect($host, $port, $persistent) {
62     if ($persistent) {
63       return @$this->memcache->pconnect($host, $port);
64     }
65     else {
66       return @$this->memcache->connect($host, $port);
67     }
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function set($key, $value, $exp = 0, $flag = FALSE) {
74     $full_key = $this->key($key);
75     return $this->memcache->set($full_key, $value, $flag, $exp);
76   }
77
78   /**
79    * {@inheritdoc}
80    */
81   public function getMulti(array $keys) {
82     $full_keys = array();
83
84     foreach ($keys as $cid) {
85       $full_key = $this->key($cid);
86       $full_keys[$cid] = $full_key;
87     }
88
89     $results = $this->memcache->get($full_keys);
90
91     // If $results is FALSE, convert it to an empty array.
92     if (!$results) {
93       $results = array();
94     }
95
96     // Convert the full keys back to the cid.
97     $cid_results = array();
98
99     // Order isn't guaranteed, so ensure the return order matches that
100     // requested. So base the results on the order of the full_keys, as they
101     // reflect the order of the $cids passed in.
102     foreach (array_intersect($full_keys, array_keys($results)) as $cid => $full_key) {
103       $cid_results[$cid] = $results[$full_key];
104     }
105
106     return $cid_results;
107   }
108
109 }