Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / memcache / src / DrupalMemcached.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\memcache\DrupalMemcached.
6  */
7
8 namespace Drupal\memcache;
9
10 /**
11  * Class DrupalMemcached.
12  */
13 class DrupalMemcached extends DrupalMemcacheBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function __construct(DrupalMemcacheConfig $settings) {
19     parent::__construct($settings);
20
21     $this->memcache = new \Memcached();
22
23     $default_opts = array(
24       \Memcached::OPT_COMPRESSION => FALSE,
25       \Memcached::OPT_DISTRIBUTION => \Memcached::DISTRIBUTION_CONSISTENT,
26     );
27     foreach ($default_opts as $key => $value) {
28       $this->memcache->setOption($key, $value);
29     }
30     // See README.txt for setting custom Memcache options when using the
31     // memcached PECL extension.
32     foreach ($this->settings->get('options', []) as $key => $value) {
33       $this->memcache->setOption($key, $value);
34     }
35
36     // SASL configuration to authenticate with Memcached.
37     // Note: this only affects the Memcached PECL extension.
38     if ($sasl_config = $this->settings->get('sasl', [])) {
39       $this->memcache->setSaslAuthData($sasl_config['username'], $sasl_config['password']);
40     }
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function addServer($server_path, $persistent = FALSE) {
47     list($host, $port) = explode(':', $server_path);
48
49     if ($host == 'unix') {
50       // Memcached expects just the path to the socket without the protocol
51       $host = substr($server_path, 7);
52       // Port is always 0 for unix sockets.
53       $port = 0;
54     }
55
56     return $this->memcache->addServer($host, $port, $persistent);
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function close() {
63     $this->memcache->quit();
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function set($key, $value, $exp = 0, $flag = FALSE) {
70     $full_key = $this->key($key);
71     return $this->memcache->set($full_key, $value, $exp);
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function getMulti(array $keys) {
78     $full_keys = array();
79
80     foreach ($keys as $cid) {
81       $full_key = $this->key($cid);
82       $full_keys[$cid] = $full_key;
83     }
84
85     if (PHP_MAJOR_VERSION === 7) {
86       $results = $this->memcache->getMulti($full_keys, \Memcached::GET_PRESERVE_ORDER);
87     } else {
88       $cas_tokens = NULL;
89       $results = $this->memcache->getMulti($full_keys, $cas_tokens, \Memcached::GET_PRESERVE_ORDER);
90     }
91
92     // If $results is FALSE, convert it to an empty array.
93     if (!$results) {
94       $results = array();
95     }
96
97     // Convert the full keys back to the cid.
98     $cid_results = array();
99     $cid_lookup = array_flip($full_keys);
100
101     foreach (array_filter($results) as $key => $value) {
102       $cid_results[$cid_lookup[$key]] = $value;
103     }
104
105     return $cid_results;
106   }
107
108 }