Metadata.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\VersionControl;
  7. /**
  8. * Class Metadata represents a list of entity fields that are applicable for persistence operations
  9. */
  10. class Metadata extends \Magento\Framework\Model\ResourceModel\Db\VersionControl\Metadata
  11. {
  12. /**
  13. * Returns list of entity fields that are applicable for persistence operations
  14. *
  15. * @param \Magento\Framework\DataObject $entity
  16. * @return array
  17. */
  18. public function getFields(\Magento\Framework\DataObject $entity)
  19. {
  20. $entityClass = get_class($entity);
  21. if (!isset($this->metadataInfo[$entityClass])) {
  22. $fields = $entity->getResource()->getConnection()->describeTable(
  23. $entity->getResource()->getEntityTable()
  24. );
  25. $fields = array_merge($fields, $entity->getAttributes());
  26. $fields = array_fill_keys(
  27. array_keys($fields),
  28. null
  29. );
  30. $this->metadataInfo[$entityClass] = $fields;
  31. }
  32. return $this->metadataInfo[$entityClass];
  33. }
  34. }