AdapterPool::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Silk\Database;
4
5
use Zend\Db\Adapter\Adapter;
6
use Zend\Db\TableGateway\Feature\GlobalAdapterFeature;
7
8
/**
9
 * AdapterPool
10
 *
11
 * @author  Lucas A. de Araújo <[email protected]>
12
 * @package Silk\Database
13
 */
14
class AdapterPool
15
{
16
    /**
17
     * Pool of adapters
18
     *
19
     * @var array
20
     */
21
    protected static $pool = [];
22
23
    /**
24
     * Construtor
25
     */
26
    public function __construct()
27
    {
28
        // Conexão com o MySQL
29
        $this->add('Default', GlobalAdapterFeature::getStaticAdapter());
30
    }
31
    
32
    /**
33
     * @param $key
34
     * @param Adapter $adapter
35
     * @return $this
36
     */
37
    public function add($key, Adapter $adapter)
38
    {
39
        self::$pool[$key] = $adapter;
40
        return $this;
41
    }
42
43
    /**
44
     * @param $key
45
     * @return $this
46
     */
47
    public function remove($key)
48
    {
49
        unset(self::$pool[$key]);
50
        return $this;
51
    }
52
53
    /**
54
     * @param $key
55
     * @return Adapter
56
     */
57
    public function get($key)
58
    {
59
        return self::$pool[$key];
60
    }
61
}
62