Test Failed
Push — master ( 485f1a...210857 )
by Lucas
02:28
created

TableGateway::updateContext()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Silk\Database;
4
5
use PhpDocReader\Reader;
6
use Silk\Exceptions\NoTableFoundException;
7
use Zend\Db\TableGateway\AbstractTableGateway;
8
use Zend\Db\TableGateway\Feature\GlobalAdapterFeature;
9
10
/**
11
 * Class TableGateway
12
 * @author  Lucas A. de Araújo <[email protected]>
13
 * @package Silk\Database
14
 */
15
class TableGateway extends AbstractTableGateway
16
{
17
    private $config;
18
19
    public function __construct($object)
20
    {
21
        $this->config = Reader::getConfig($object);
22
23
        if (!array_key_exists('table', $this->config))
24
            throw new NoTableFoundException();
25
26
        $this->table = $this->config['table'];
27
        $this->adapter = GlobalAdapterFeature::getStaticAdapter();
28
29
        $this->updateContext();
30
    }
31
32
    protected function updateContext()
33
    {
34
        if(isset($this->config['schema'])){
35
            $sql = 'USE ' . $this->config['schema'] . ';';
36
            $this->adapter->getDriver()->getConnection()->execute($sql);
37
        }
38
    }
39
}