ZfQueryBasedTable: allow for ZfAdapter instances

This commit is contained in:
Thomas Gelf 2017-09-17 14:06:07 +02:00
parent aee72c558c
commit 8f1f3ec699
1 changed files with 15 additions and 4 deletions

View File

@ -4,6 +4,7 @@ namespace ipl\Web\Table;
use Icinga\Data\Db\DbConnection; use Icinga\Data\Db\DbConnection;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\ProgrammingError;
use ipl\Db\Zf1\FilterRenderer; use ipl\Db\Zf1\FilterRenderer;
use ipl\Db\Zf1\SelectPaginationAdapter; use ipl\Db\Zf1\SelectPaginationAdapter;
use ipl\Html\Container; use ipl\Html\Container;
@ -12,21 +13,31 @@ use ipl\Html\Html;
use ipl\Html\Link; use ipl\Html\Link;
use ipl\Web\Widget\ControlsAndContent; use ipl\Web\Widget\ControlsAndContent;
use ipl\Web\Url; use ipl\Web\Url;
use Zend_Db_Adapter_Abstract as DbAdapter;
abstract class ZfQueryBasedTable extends QueryBasedTable abstract class ZfQueryBasedTable extends QueryBasedTable
{ {
/** @var DbConnection */ /** @var DbConnection */
private $connection; private $connection;
/** @var \Zend_Db_Adapter_Abstract */ /** @var DbAdapter */
private $db; private $db;
private $query; private $query;
public function __construct(DbConnection $connection) public function __construct($db)
{ {
$this->connection = $connection; if ($db instanceof DbAdapter) {
$this->db = $connection->getDbAdapter(); $this->db = $db;
} elseif ($db instanceof DbConnection) {
$this->connection = $db;
$this->db = $db->getDbAdapter();
} else {
throw new ProgrammingError(
'Unable to deal with %s db class',
get_class($db)
);
}
} }
public static function show(ControlsAndContent $controller, DbConnection $db) public static function show(ControlsAndContent $controller, DbConnection $db)