Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReadRow.php
Go to the documentation of this file.
1 <?php
8 
11 
15 class ReadRow
16 {
20  private $metadataPool;
21 
25  private $resourceConnection;
26 
33  public function __construct(
34  MetadataPool $metadataPool,
35  ResourceConnection $resourceConnection
36  ) {
37  $this->metadataPool = $metadataPool;
38  $this->resourceConnection = $resourceConnection;
39  }
40 
48  public function execute($entityType, $identifier, $context = [])
49  {
50  $metadata = $this->metadataPool->getMetadata($entityType);
51  $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
52  $select = $connection->select()
53  ->from(['t' => $metadata->getEntityTable()])
54  ->where($metadata->getIdentifierField() . ' = ?', $identifier);
55  foreach ($context as $field => $value) {
56  $select->where(
57  $connection->quoteIdentifier($field) . ' = ?',
58  $value
59  );
60  }
61  $data = $connection->fetchRow($select);
62  return $data ?: [];
63  }
64 }
execute($entityType, $identifier, $context=[])
Definition: ReadRow.php:48
$value
Definition: gender.phtml:16
__construct(MetadataPool $metadataPool, ResourceConnection $resourceConnection)
Definition: ReadRow.php:33
$connection
Definition: bulk.php:13