Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SubSelect.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Framework\DB;
7 
10 
14 class SubSelect extends \Zend_Db_Expr
15 {
19  protected $table;
20 
24  protected $columns;
25 
29  protected $originColumn;
30 
34  protected $targetColumn;
35 
39  protected $resource;
40 
44  protected $connectionName;
45 
49  protected $connection;
50 
59  public function __construct(
61  $table,
62  array $columns,
66  ) {
67  $this->resource = $resource;
68  $this->connectionName = $connectionName;
69  $this->table = $table;
70  $this->columns = $columns;
71  $this->originColumn = $originColumn;
72  $this->targetColumn = $targetColumn;
73  }
74 
78  public function __toString()
79  {
80  $select = $this->getConnection()->select()->from(
81  $this->resource->getTableName($this->table),
82  array_values($this->columns)
83  )->where(
84  sprintf(
85  '%s = %s',
86  $this->getConnection()->quoteIdentifier($this->originColumn),
87  $this->getConnection()->quoteIdentifier($this->targetColumn)
88  )
89  )->limit(1);
90  return sprintf('(%s)', $select);
91  }
92 
98  protected function getConnection()
99  {
100  if (!$this->connection) {
101  $this->connection = $this->resource->getConnection($this->connectionName);
102  }
103  return $this->connection;
104  }
105 }
__construct(ResourceConnection $resource, $table, array $columns, $originColumn, $targetColumn, $connectionName=ResourceConnection::DEFAULT_CONNECTION)
Definition: SubSelect.php:59