Skip to content

Commit

Permalink
Update TableGateway.php
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdearaujo committed Nov 16, 2017
1 parent f4c35af commit 7f877fb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Silk/Database/TableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,26 +17,29 @@ class TableGateway extends AbstractTableGateway
{
private $config;

public function __construct($object, $adapter = null)
public function __construct($object)
{
$this->config = Reader::getConfig($object);

if (!array_key_exists('table', $this->config))
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);
}
Expand Down

0 comments on commit 7f877fb

Please sign in to comment.