Document.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Api\Search;
  7. use Magento\Framework\Api\AbstractSimpleObject;
  8. /**
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Document extends AbstractSimpleObject implements DocumentInterface, \IteratorAggregate
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function getId()
  18. {
  19. return $this->_get(self::ID);
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function setId($id)
  25. {
  26. return $this->setData(self::ID, $id);
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function getCustomAttribute($attributeCode)
  32. {
  33. return $this->_data[self::CUSTOM_ATTRIBUTES][$attributeCode] ?? null;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function setCustomAttribute($attributeCode, $attributeValue)
  39. {
  40. /** @var \Magento\Framework\Api\AttributeInterface[] $attributes */
  41. $attributes = $this->getCustomAttributes();
  42. $attributes[$attributeCode] = $attributeValue;
  43. return $this->setCustomAttributes($attributes);
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function getCustomAttributes()
  49. {
  50. return $this->_get(self::CUSTOM_ATTRIBUTES);
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function setCustomAttributes(array $attributes)
  56. {
  57. return $this->setData(self::CUSTOM_ATTRIBUTES, $attributes);
  58. }
  59. /**
  60. * Implementation of \IteratorAggregate::getIterator()
  61. *
  62. * @return \ArrayIterator
  63. * @since 100.1.0
  64. */
  65. public function getIterator()
  66. {
  67. $attributes = (array)$this->getCustomAttributes();
  68. return new \ArrayIterator($attributes);
  69. }
  70. }