annotate vendor/consolidation/annotated-command/src/Cache/CacheWrapper.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2 namespace Consolidation\AnnotatedCommand\Cache;
Chris@0 3
Chris@0 4 /**
Chris@0 5 * Make a generic cache object conform to our expected interface.
Chris@0 6 */
Chris@0 7 class CacheWrapper implements SimpleCacheInterface
Chris@0 8 {
Chris@0 9 protected $dataStore;
Chris@0 10
Chris@0 11 public function __construct($dataStore)
Chris@0 12 {
Chris@0 13 $this->dataStore = $dataStore;
Chris@0 14 }
Chris@0 15
Chris@0 16 /**
Chris@0 17 * Test for an entry from the cache
Chris@0 18 * @param string $key
Chris@0 19 * @return boolean
Chris@0 20 */
Chris@0 21 public function has($key)
Chris@0 22 {
Chris@0 23 if (method_exists($this->dataStore, 'has')) {
Chris@0 24 return $this->dataStore->has($key);
Chris@0 25 }
Chris@0 26 $test = $this->dataStore->get($key);
Chris@0 27 return !empty($test);
Chris@0 28 }
Chris@0 29
Chris@0 30 /**
Chris@0 31 * Get an entry from the cache
Chris@0 32 * @param string $key
Chris@0 33 * @return array
Chris@0 34 */
Chris@0 35 public function get($key)
Chris@0 36 {
Chris@0 37 return (array) $this->dataStore->get($key);
Chris@0 38 }
Chris@0 39
Chris@0 40 /**
Chris@0 41 * Store an entry in the cache
Chris@0 42 * @param string $key
Chris@0 43 * @param array $data
Chris@0 44 */
Chris@0 45 public function set($key, $data)
Chris@0 46 {
Chris@0 47 $this->dataStore->set($key, $data);
Chris@0 48 }
Chris@0 49 }