CacheWrapper.php 1.0 KB

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