Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Cache / Storage / Adapter / AbstractZendServer.php
blob9e20d58ae5d5385bbae4ce9c208bb7147945aaae
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Cache\Storage\Adapter;
12 use stdClass;
13 use Zend\Cache\Exception;
14 use Zend\Cache\Storage\Capabilities;
16 abstract class AbstractZendServer extends AbstractAdapter
18 /**
19 * The namespace separator used on Zend Data Cache functions
21 * @var string
23 const NAMESPACE_SEPARATOR = '::';
25 /* reading */
27 /**
28 * Internal method to get an item.
30 * @param string $normalizedKey
31 * @param bool $success
32 * @param mixed $casToken
33 * @return mixed Data on success, null on failure
34 * @throws Exception\ExceptionInterface
36 protected function internalGetItem(& $normalizedKey, & $success = null, & $casToken = null)
38 $namespace = $this->getOptions()->getNamespace();
39 $prefix = ($namespace === '') ? '' : $namespace . self::NAMESPACE_SEPARATOR;
41 $result = $this->zdcFetch($prefix . $normalizedKey);
42 if ($result === false) {
43 $success = false;
44 $result = null;
45 } else {
46 $success = true;
47 $casToken = $result;
50 return $result;
53 /**
54 * Internal method to get multiple items.
56 * @param array $normalizedKeys
57 * @return array Associative array of keys and values
58 * @throws Exception\ExceptionInterface
60 protected function internalGetItems(array & $normalizedKeys)
62 $namespace = $this->getOptions()->getNamespace();
63 if ($namespace === '') {
64 return $this->zdcFetchMulti($normalizedKeys);
67 $prefix = $namespace . self::NAMESPACE_SEPARATOR;
68 $internalKeys = array();
69 foreach ($normalizedKeys as $normalizedKey) {
70 $internalKeys[] = $prefix . $normalizedKey;
73 $fetch = $this->zdcFetchMulti($internalKeys);
74 $result = array();
75 $prefixL = strlen($prefix);
76 foreach ($fetch as $k => & $v) {
77 $result[substr($k, $prefixL)] = $v;
80 return $result;
83 /**
84 * Internal method to test if an item exists.
86 * @param string $normalizedKey
87 * @return bool
88 * @throws Exception\ExceptionInterface
90 protected function internalHasItem(& $normalizedKey)
92 $namespace = $this->getOptions()->getNamespace();
93 $prefix = ($namespace === '') ? '' : $namespace . self::NAMESPACE_SEPARATOR;
94 return ($this->zdcFetch($prefix . $normalizedKey) !== false);
97 /**
98 * Internal method to test multiple items.
100 * @param array $normalizedKeys
101 * @return array Array of found keys
102 * @throws Exception\ExceptionInterface
104 protected function internalHasItems(array & $normalizedKeys)
106 $namespace = $this->getOptions()->getNamespace();
107 if ($namespace === '') {
108 return array_keys($this->zdcFetchMulti($normalizedKeys));
111 $prefix = $namespace . self::NAMESPACE_SEPARATOR;
112 $internalKeys = array();
113 foreach ($normalizedKeys as $normalizedKey) {
114 $internalKeys[] = $prefix . $normalizedKey;
117 $fetch = $this->zdcFetchMulti($internalKeys);
118 $result = array();
119 $prefixL = strlen($prefix);
120 foreach ($fetch as $internalKey => & $value) {
121 $result[] = substr($internalKey, $prefixL);
124 return $result;
128 * Get metadata for multiple items
130 * @param array $normalizedKeys
131 * @return array Associative array of keys and metadata
133 * @triggers getMetadatas.pre(PreEvent)
134 * @triggers getMetadatas.post(PostEvent)
135 * @triggers getMetadatas.exception(ExceptionEvent)
137 protected function internalGetMetadatas(array & $normalizedKeys)
139 $namespace = $this->getOptions()->getNamespace();
140 if ($namespace === '') {
141 $result = $this->zdcFetchMulti($normalizedKeys);
142 return array_fill_keys(array_keys($result), array());
145 $prefix = $namespace . self::NAMESPACE_SEPARATOR;
146 $internalKeys = array();
147 foreach ($normalizedKeys as $normalizedKey) {
148 $internalKeys[] = $prefix . $normalizedKey;
151 $fetch = $this->zdcFetchMulti($internalKeys);
152 $result = array();
153 $prefixL = strlen($prefix);
154 foreach ($fetch as $internalKey => $value) {
155 $result[substr($internalKey, $prefixL)] = array();
158 return $result;
161 /* writing */
164 * Internal method to store an item.
166 * @param string $normalizedKey
167 * @param mixed $value
168 * @return bool
169 * @throws Exception\ExceptionInterface
171 protected function internalSetItem(& $normalizedKey, & $value)
173 $options = $this->getOptions();
174 $namespace = $options->getNamespace();
175 $prefix = ($namespace === '') ? '' : $namespace . self::NAMESPACE_SEPARATOR;
176 $this->zdcStore($prefix . $normalizedKey, $value, $options->getTtl());
177 return true;
181 * Internal method to remove an item.
183 * @param string $normalizedKey
184 * @return bool
185 * @throws Exception\ExceptionInterface
187 protected function internalRemoveItem(& $normalizedKey)
189 $namespace = $this->getOptions()->getNamespace();
190 $prefix = ($namespace === '') ? '' : $namespace . self::NAMESPACE_SEPARATOR;
191 return $this->zdcDelete($prefix . $normalizedKey);
194 /* status */
197 * Internal method to get capabilities of this adapter
199 * @return Capabilities
201 protected function internalGetCapabilities()
203 if ($this->capabilities === null) {
204 $this->capabilityMarker = new stdClass();
205 $this->capabilities = new Capabilities(
206 $this,
207 $this->capabilityMarker,
208 array(
209 'supportedDatatypes' => array(
210 'NULL' => true,
211 'boolean' => true,
212 'integer' => true,
213 'double' => true,
214 'string' => true,
215 'array' => true,
216 'object' => 'object',
217 'resource' => false,
219 'supportedMetadata' => array(),
220 'maxTtl' => 0,
221 'staticTtl' => true,
222 'ttlPrecision' => 1,
223 'useRequestTime' => false,
224 'expiredRead' => false,
225 'maxKeyLength' => 0,
226 'namespaceIsPrefix' => true,
227 'namespaceSeparator' => self::NAMESPACE_SEPARATOR,
232 return $this->capabilities;
235 /* internal wrapper of zend_[disk|shm]_cache_* functions */
238 * Store data into Zend Data Cache (zdc)
240 * @param string $internalKey
241 * @param mixed $value
242 * @param int $ttl
243 * @return void
244 * @throws Exception\RuntimeException
246 abstract protected function zdcStore($internalKey, $value, $ttl);
249 * Fetch a single item from Zend Data Cache (zdc)
251 * @param string $internalKey
252 * @return mixed The stored value or FALSE if item wasn't found
253 * @throws Exception\RuntimeException
255 abstract protected function zdcFetch($internalKey);
258 * Fetch multiple items from Zend Data Cache (zdc)
260 * @param array $internalKeys
261 * @return array All found items
262 * @throws Exception\RuntimeException
264 abstract protected function zdcFetchMulti(array $internalKeys);
267 * Delete data from Zend Data Cache (zdc)
269 * @param string $internalKey
270 * @return bool
271 * @throws Exception\RuntimeException
273 abstract protected function zdcDelete($internalKey);