CustomerCodeRegistry.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Registry;
  7. /**
  8. * Maintains a state of customer ID and customer codes to prevent extraneous calls to the database
  9. */
  10. class CustomerCodeRegistry
  11. {
  12. /** @var string[] Indexed by Customer ID */
  13. private $registry = [];
  14. /**
  15. * Retrieve a customer code stored in the registry
  16. *
  17. * @param string $customerId
  18. * @return bool|string
  19. */
  20. public function get($customerId)
  21. {
  22. if (array_key_exists($customerId, $this->registry)) {
  23. return $this->registry[$customerId];
  24. }
  25. return false;
  26. }
  27. /**
  28. * Store a customer code in the registry
  29. *
  30. * @param string $customerId
  31. * @param string $customerCode
  32. * @return CustomerCodeRegistry
  33. */
  34. public function set($customerId, $customerCode)
  35. {
  36. $this->registry[$customerId] = $customerCode;
  37. return $this;
  38. }
  39. /**
  40. * Delete a customer code from the registry
  41. *
  42. * @param string $customerId
  43. * @return CustomerCodeRegistry
  44. */
  45. public function delete($customerId)
  46. {
  47. unset($this->registry[$customerId]);
  48. return $this;
  49. }
  50. }