Metadata.php 1.2 KB

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