1<?php 2/** 3 * Zend Framework (http://framework.zend.com/) 4 * 5 * @link http://github.com/zendframework/zf2 for the canonical source repository 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 7 * @license http://framework.zend.com/license/new-bsd New BSD License 8 */ 9 10namespace Zend\Cache\Storage\Adapter; 11 12use stdClass; 13use Zend\Cache\Storage\AvailableSpaceCapableInterface; 14use Zend\Cache\Storage\Capabilities; 15use Zend\Cache\Storage\ClearByNamespaceInterface; 16use Zend\Cache\Storage\ClearByPrefixInterface; 17use Zend\Cache\Storage\ClearExpiredInterface; 18use Zend\Cache\Storage\FlushableInterface; 19use Zend\Cache\Storage\IterableInterface; 20use Zend\Cache\Storage\OptimizableInterface; 21use Zend\Cache\Storage\StorageInterface; 22use Zend\Cache\Storage\TaggableInterface; 23use Zend\Cache\Storage\TotalSpaceCapableInterface; 24 25class BlackHole implements 26 StorageInterface, 27 AvailableSpaceCapableInterface, 28 ClearByNamespaceInterface, 29 ClearByPrefixInterface, 30 ClearExpiredInterface, 31 FlushableInterface, 32 IterableInterface, 33 OptimizableInterface, 34 TaggableInterface, 35 TotalSpaceCapableInterface 36{ 37 /** 38 * Capabilities of this adapter 39 * 40 * @var null|Capabilities 41 */ 42 protected $capabilities = null; 43 44 /** 45 * Marker to change capabilities 46 * 47 * @var null|object 48 */ 49 protected $capabilityMarker; 50 51 /** 52 * options 53 * 54 * @var null|AdapterOptions 55 */ 56 protected $options; 57 58 /** 59 * Constructor 60 * 61 * @param null|array|\Traversable|AdapterOptions $options 62 */ 63 public function __construct($options = null) 64 { 65 if ($options) { 66 $this->setOptions($options); 67 } 68 } 69 70 /** 71 * Set options. 72 * 73 * @param array|\Traversable|AdapterOptions $options 74 * @return StorageInterface Fluent interface 75 */ 76 public function setOptions($options) 77 { 78 if ($this->options !== $options) { 79 if (!$options instanceof AdapterOptions) { 80 $options = new AdapterOptions($options); 81 } 82 83 if ($this->options) { 84 $this->options->setAdapter(null); 85 } 86 $options->setAdapter($this); 87 $this->options = $options; 88 } 89 return $this; 90 } 91 92 /** 93 * Get options 94 * 95 * @return AdapterOptions 96 */ 97 public function getOptions() 98 { 99 if (!$this->options) { 100 $this->setOptions(new AdapterOptions()); 101 } 102 return $this->options; 103 } 104 105 /** 106 * Get an item. 107 * 108 * @param string $key 109 * @param bool $success 110 * @param mixed $casToken 111 * @return mixed Data on success, null on failure 112 */ 113 public function getItem($key, & $success = null, & $casToken = null) 114 { 115 $success = false; 116 return; 117 } 118 119 /** 120 * Get multiple items. 121 * 122 * @param array $keys 123 * @return array Associative array of keys and values 124 */ 125 public function getItems(array $keys) 126 { 127 return array(); 128 } 129 130 /** 131 * Test if an item exists. 132 * 133 * @param string $key 134 * @return bool 135 */ 136 public function hasItem($key) 137 { 138 return false; 139 } 140 141 /** 142 * Test multiple items. 143 * 144 * @param array $keys 145 * @return array Array of found keys 146 */ 147 public function hasItems(array $keys) 148 { 149 return array(); 150 } 151 152 /** 153 * Get metadata of an item. 154 * 155 * @param string $key 156 * @return array|bool Metadata on success, false on failure 157 */ 158 public function getMetadata($key) 159 { 160 return false; 161 } 162 163 /** 164 * Get multiple metadata 165 * 166 * @param array $keys 167 * @return array Associative array of keys and metadata 168 */ 169 public function getMetadatas(array $keys) 170 { 171 return array(); 172 } 173 174 /** 175 * Store an item. 176 * 177 * @param string $key 178 * @param mixed $value 179 * @return bool 180 */ 181 public function setItem($key, $value) 182 { 183 return false; 184 } 185 186 /** 187 * Store multiple items. 188 * 189 * @param array $keyValuePairs 190 * @return array Array of not stored keys 191 */ 192 public function setItems(array $keyValuePairs) 193 { 194 return array_keys($keyValuePairs); 195 } 196 197 /** 198 * Add an item. 199 * 200 * @param string $key 201 * @param mixed $value 202 * @return bool 203 */ 204 public function addItem($key, $value) 205 { 206 return false; 207 } 208 209 /** 210 * Add multiple items. 211 * 212 * @param array $keyValuePairs 213 * @return array Array of not stored keys 214 */ 215 public function addItems(array $keyValuePairs) 216 { 217 return array_keys($keyValuePairs); 218 } 219 220 /** 221 * Replace an existing item. 222 * 223 * @param string $key 224 * @param mixed $value 225 * @return bool 226 */ 227 public function replaceItem($key, $value) 228 { 229 return false; 230 } 231 232 /** 233 * Replace multiple existing items. 234 * 235 * @param array $keyValuePairs 236 * @return array Array of not stored keys 237 */ 238 public function replaceItems(array $keyValuePairs) 239 { 240 return array_keys($keyValuePairs); 241 } 242 243 /** 244 * Set an item only if token matches 245 * 246 * It uses the token received from getItem() to check if the item has 247 * changed before overwriting it. 248 * 249 * @param mixed $token 250 * @param string $key 251 * @param mixed $value 252 * @return bool 253 */ 254 public function checkAndSetItem($token, $key, $value) 255 { 256 return false; 257 } 258 259 /** 260 * Reset lifetime of an item 261 * 262 * @param string $key 263 * @return bool 264 */ 265 public function touchItem($key) 266 { 267 return false; 268 } 269 270 /** 271 * Reset lifetime of multiple items. 272 * 273 * @param array $keys 274 * @return array Array of not updated keys 275 */ 276 public function touchItems(array $keys) 277 { 278 return $keys; 279 } 280 281 /** 282 * Remove an item. 283 * 284 * @param string $key 285 * @return bool 286 */ 287 public function removeItem($key) 288 { 289 return false; 290 } 291 292 /** 293 * Remove multiple items. 294 * 295 * @param array $keys 296 * @return array Array of not removed keys 297 */ 298 public function removeItems(array $keys) 299 { 300 return $keys; 301 } 302 303 /** 304 * Increment an item. 305 * 306 * @param string $key 307 * @param int $value 308 * @return int|bool The new value on success, false on failure 309 */ 310 public function incrementItem($key, $value) 311 { 312 return false; 313 } 314 315 /** 316 * Increment multiple items. 317 * 318 * @param array $keyValuePairs 319 * @return array Associative array of keys and new values 320 */ 321 public function incrementItems(array $keyValuePairs) 322 { 323 return array(); 324 } 325 326 /** 327 * Decrement an item. 328 * 329 * @param string $key 330 * @param int $value 331 * @return int|bool The new value on success, false on failure 332 */ 333 public function decrementItem($key, $value) 334 { 335 return false; 336 } 337 338 /** 339 * Decrement multiple items. 340 * 341 * @param array $keyValuePairs 342 * @return array Associative array of keys and new values 343 */ 344 public function decrementItems(array $keyValuePairs) 345 { 346 return array(); 347 } 348 349 /** 350 * Capabilities of this storage 351 * 352 * @return Capabilities 353 */ 354 public function getCapabilities() 355 { 356 if ($this->capabilities === null) { 357 // use default capabilities only 358 $this->capabilityMarker = new stdClass(); 359 $this->capabilities = new Capabilities($this, $this->capabilityMarker); 360 } 361 return $this->capabilities; 362 } 363 364 /* AvailableSpaceCapableInterface */ 365 366 /** 367 * Get available space in bytes 368 * 369 * @return int|float 370 */ 371 public function getAvailableSpace() 372 { 373 return 0; 374 } 375 376 /* ClearByNamespaceInterface */ 377 378 /** 379 * Remove items of given namespace 380 * 381 * @param string $namespace 382 * @return bool 383 */ 384 public function clearByNamespace($namespace) 385 { 386 return false; 387 } 388 389 /* ClearByPrefixInterface */ 390 391 /** 392 * Remove items matching given prefix 393 * 394 * @param string $prefix 395 * @return bool 396 */ 397 public function clearByPrefix($prefix) 398 { 399 return false; 400 } 401 402 /* ClearExpiredInterface */ 403 404 /** 405 * Remove expired items 406 * 407 * @return bool 408 */ 409 public function clearExpired() 410 { 411 return false; 412 } 413 414 /* FlushableInterface */ 415 416 /** 417 * Flush the whole storage 418 * 419 * @return bool 420 */ 421 public function flush() 422 { 423 return false; 424 } 425 426 /* IterableInterface */ 427 428 /** 429 * Get the storage iterator 430 * 431 * @return KeyListIterator 432 */ 433 public function getIterator() 434 { 435 return new KeyListIterator($this, array()); 436 } 437 438 /* OptimizableInterface */ 439 440 /** 441 * Optimize the storage 442 * 443 * @return bool 444 */ 445 public function optimize() 446 { 447 return false; 448 } 449 450 /* TaggableInterface */ 451 452 /** 453 * Set tags to an item by given key. 454 * An empty array will remove all tags. 455 * 456 * @param string $key 457 * @param string[] $tags 458 * @return bool 459 */ 460 public function setTags($key, array $tags) 461 { 462 return false; 463 } 464 465 /** 466 * Get tags of an item by given key 467 * 468 * @param string $key 469 * @return string[]|FALSE 470 */ 471 public function getTags($key) 472 { 473 return false; 474 } 475 476 /** 477 * Remove items matching given tags. 478 * 479 * If $disjunction only one of the given tags must match 480 * else all given tags must match. 481 * 482 * @param string[] $tags 483 * @param bool $disjunction 484 * @return bool 485 */ 486 public function clearByTags(array $tags, $disjunction = false) 487 { 488 return false; 489 } 490 491 /* TotalSpaceCapableInterface */ 492 493 /** 494 * Get total space in bytes 495 * 496 * @return int|float 497 */ 498 public function getTotalSpace() 499 { 500 return 0; 501 } 502} 503