GenericStorage.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Model\TaxRegistry;
  7. /**
  8. * Generic framework-registry-based storage for Vertex tax information.
  9. */
  10. class GenericStorage implements StorageInterface
  11. {
  12. /**
  13. * Internal storage for tax data.
  14. *
  15. * @var array
  16. */
  17. protected $data = [];
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function get($key, $default = null)
  22. {
  23. return isset($this->data[$key]) ? $this->data[$key] : $default;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. *
  28. * @SuppressWarnings(PHPMD.UnusedFormalParameter) Lifetime not supported for generic storage.
  29. */
  30. public function set($key, $value, $lifetime = 0)
  31. {
  32. if (isset($this->data[$key])) {
  33. return false;
  34. }
  35. $this->data[$key] = $value;
  36. return true;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function unsetData($key)
  42. {
  43. if (isset($this->data[$key])) {
  44. unset($this->data[$key]);
  45. return true;
  46. }
  47. return false;
  48. }
  49. }