EntityRegistry.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Model;
  7. /**
  8. * Class EntityRegistry
  9. */
  10. class EntityRegistry
  11. {
  12. /**
  13. * @var array
  14. */
  15. protected $registry = [];
  16. /**
  17. * Register entity
  18. *
  19. * @param string $entityType
  20. * @param string $identifier
  21. * @param object $entity
  22. * @return void
  23. */
  24. public function register($entityType, $identifier, $entity)
  25. {
  26. $this->registry[$entityType][$identifier] = $entity;
  27. }
  28. /**
  29. * Retrieve entity from storage
  30. *
  31. * @param string $entityType
  32. * @param string $identifier
  33. * @return null|object
  34. */
  35. public function retrieve($entityType, $identifier)
  36. {
  37. if (isset($this->registry[$entityType][$identifier])) {
  38. return $this->registry[$entityType][$identifier];
  39. } else {
  40. return null;
  41. }
  42. }
  43. /**
  44. * Remove entity from registry
  45. *
  46. * @param string $entityType
  47. * @param string $identifier
  48. * @return bool
  49. */
  50. public function remove($entityType, $identifier)
  51. {
  52. if (isset($this->registry[$entityType][$identifier])) {
  53. unset($this->registry[$entityType][$identifier]);
  54. }
  55. return true;
  56. }
  57. }