From 7f877fbb27d58dcc63a378d34ea3e7efd6139ff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20de=20Ara=C3=BAjo?= Date: Thu, 16 Nov 2017 14:37:07 -0200 Subject: [PATCH] Update TableGateway.php --- src/Silk/Database/TableGateway.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Silk/Database/TableGateway.php b/src/Silk/Database/TableGateway.php index 9129175..f3cccf0 100644 --- a/src/Silk/Database/TableGateway.php +++ b/src/Silk/Database/TableGateway.php @@ -6,6 +6,7 @@ use Silk\Exceptions\NoTableFoundException; use Zend\Db\TableGateway\AbstractTableGateway; use Zend\Db\TableGateway\Feature\GlobalAdapterFeature; +use Silk\Database\AdapterPool; /** * Class TableGateway @@ -16,7 +17,7 @@ class TableGateway extends AbstractTableGateway { private $config; - public function __construct($object, $adapter = null) + public function __construct($object) { $this->config = Reader::getConfig($object); @@ -24,18 +25,21 @@ public function __construct($object, $adapter = null) throw new NoTableFoundException(); $this->table = $this->config['table']; + + if(!isset($this->config['adapter'])) + $this->config['adapter'] = 'Default'; - if(!empty($adapter)) - $this->adapter = $adapter; - else - $this->adapter = GlobalAdapterFeature::getStaticAdapter(); + $adapterPool = new AdapterPool(); + $this->adapter = $adapterPool->get($this->config['adapter']); $this->updateContext(); } protected function updateContext() { - if(isset($this->config['schema'])){ + $platform = $this->adapter->getPlatform()->getName(); + + if(isset($this->config['schema']) && $platform == 'MySQL'){ $sql = 'USE ' . $this->config['schema'] . ';'; $this->adapter->getDriver()->getConnection()->execute($sql); }