2023-03-11 12:04:29 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Zend Framework (http://framework.zend.com/)
|
|
|
|
*
|
|
|
|
* @link http://github.com/zendframework/zf2 for the canonical source repository
|
2023-04-01 09:03:34 +03:00
|
|
|
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
2023-03-11 12:04:29 +03:00
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Zend\Db\TableGateway;
|
|
|
|
|
|
|
|
use Zend\Db\Adapter\AdapterInterface;
|
|
|
|
use Zend\Db\ResultSet\ResultSet;
|
|
|
|
use Zend\Db\ResultSet\ResultSetInterface;
|
|
|
|
use Zend\Db\Sql\Sql;
|
|
|
|
use Zend\Db\Sql\TableIdentifier;
|
|
|
|
|
|
|
|
class TableGateway extends AbstractTableGateway
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2023-04-01 09:03:34 +03:00
|
|
|
* @param string|TableIdentifier|array $table
|
|
|
|
* @param AdapterInterface $adapter
|
|
|
|
* @param Feature\AbstractFeature|Feature\FeatureSet|Feature\AbstractFeature[]|null $features
|
|
|
|
* @param ResultSetInterface|null $resultSetPrototype
|
|
|
|
* @param Sql|null $sql
|
|
|
|
*
|
2023-03-11 12:04:29 +03:00
|
|
|
* @throws Exception\InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function __construct($table, AdapterInterface $adapter, $features = null, ResultSetInterface $resultSetPrototype = null, Sql $sql = null)
|
|
|
|
{
|
|
|
|
// table
|
2023-04-01 09:03:34 +03:00
|
|
|
if (!(is_string($table) || $table instanceof TableIdentifier || is_array($table))) {
|
2023-03-11 12:04:29 +03:00
|
|
|
throw new Exception\InvalidArgumentException('Table name must be a string or an instance of Zend\Db\Sql\TableIdentifier');
|
|
|
|
}
|
|
|
|
$this->table = $table;
|
|
|
|
|
|
|
|
// adapter
|
|
|
|
$this->adapter = $adapter;
|
|
|
|
|
|
|
|
// process features
|
|
|
|
if ($features !== null) {
|
|
|
|
if ($features instanceof Feature\AbstractFeature) {
|
|
|
|
$features = array($features);
|
|
|
|
}
|
|
|
|
if (is_array($features)) {
|
|
|
|
$this->featureSet = new Feature\FeatureSet($features);
|
|
|
|
} elseif ($features instanceof Feature\FeatureSet) {
|
|
|
|
$this->featureSet = $features;
|
|
|
|
} else {
|
|
|
|
throw new Exception\InvalidArgumentException(
|
|
|
|
'TableGateway expects $feature to be an instance of an AbstractFeature or a FeatureSet, or an array of AbstractFeatures'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->featureSet = new Feature\FeatureSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
// result prototype
|
|
|
|
$this->resultSetPrototype = ($resultSetPrototype) ?: new ResultSet;
|
|
|
|
|
|
|
|
// Sql object (factory for select, insert, update, delete)
|
|
|
|
$this->sql = ($sql) ?: new Sql($this->adapter, $this->table);
|
|
|
|
|
|
|
|
// check sql object bound to same table
|
|
|
|
if ($this->sql->getTable() != $this->table) {
|
|
|
|
throw new Exception\InvalidArgumentException('The table inside the provided Sql object must match the table of this TableGateway');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->initialize();
|
|
|
|
}
|
|
|
|
}
|