TableData.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\TestFramework\Deploy;
  7. use Magento\Framework\App\ResourceConnection;
  8. /**
  9. * The purpose of this class is to describe what data is in table
  10. */
  11. class TableData
  12. {
  13. /**
  14. * @var ResourceConnection
  15. */
  16. private $resourceConnection;
  17. /**
  18. * TableData constructor.
  19. * @param ResourceConnection $resourceConnection
  20. */
  21. public function __construct(ResourceConnection $resourceConnection)
  22. {
  23. $this->resourceConnection = $resourceConnection;
  24. }
  25. /**
  26. * @param string $tableName
  27. * @param string $columnName
  28. * @return array
  29. */
  30. public function describeTableData($tableName, $columnName = null)
  31. {
  32. $adapter = $this->resourceConnection->getConnection();
  33. $cols = $columnName ?: '*';
  34. $select = $adapter
  35. ->select()
  36. ->from($tableName, $cols);
  37. return $columnName ? $adapter->fetchCol($select) : $adapter->fetchAll($select);
  38. }
  39. }