ObjectRegistry.php 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\CatalogUrlRewrite\Model;
  7. /**
  8. * Class ObjectRegistry
  9. */
  10. class ObjectRegistry
  11. {
  12. /**
  13. * Key is id of entity, value is entity
  14. *
  15. * @var \Magento\Framework\DataObject[]
  16. */
  17. protected $entitiesMap;
  18. /**
  19. * @param \Magento\Framework\DataObject[] $entities
  20. */
  21. public function __construct($entities)
  22. {
  23. $this->entitiesMap = [];
  24. foreach ($entities as $entity) {
  25. $this->entitiesMap[$entity->getId()] = $entity;
  26. }
  27. }
  28. /**
  29. * Get Entity
  30. *
  31. * @param int $entityId
  32. * @return \Magento\Framework\DataObject|null
  33. */
  34. public function get($entityId)
  35. {
  36. return $this->entitiesMap[$entityId] ?? null;
  37. }
  38. /**
  39. * List Entities
  40. *
  41. * @return \Magento\Framework\DataObject[]
  42. */
  43. public function getList()
  44. {
  45. return $this->entitiesMap;
  46. }
  47. }