Completed
Push — master ( 58c9ab...b3ba9b )
by Sébastien
19:11 queued 01:31
created

Capsule5Connection::getResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Soluble\DbWrapper\Connection\Laravel;
4
5
use Soluble\DbWrapper\Adapter\AdapterInterface;
6
use Soluble\DbWrapper\Exception;
7
use Soluble\DbWrapper\Connection\ConnectionInterface;
8
9
class Capsule5Connection implements ConnectionInterface
10
{
11
12
    /**
13
     *
14
     * @var AdapterInterface;
15
     */
16
    protected $adapter;
17
18
    /**
19
     *
20
     * @var \Illuminate\Database\Capsule\Manager;
21
     */
22
    protected $capsule;
23
24
25
    /**
26
     * @param AdapterInterface $adapter
27
     * @param \Illuminate\Database\Capsule\Manager $capsule
28
     */
29
    public function __construct(AdapterInterface $adapter, \Illuminate\Database\Capsule\Manager $capsule)
30
    {
31
        $this->adapter = $adapter;
32
        $this->capsule = $capsule;
33
    }
34
35
36
    /**
37
     * {@inheritdoc}
38
     * @return \PDO
39
     */
40
    public function getResource()
41
    {
42
        return $this->capsule->getConnection()->getPdo();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     * @throws Exception\UnsupportedFeatureException
48
     */
49
    public function getHost()
50
    {
51
        throw new Exception\UnsupportedFeatureException(__METHOD__ . " is not (yet) supported for capsule bridge");
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     * @throws Exception\RuntimeException
57
     * @return string
58
     */
59
    public function getCurrentSchema()
60
    {
61
        try {
62
            $schema = $this->capsule->getConnection()->getDatabaseName();
63
        } catch (\Exception $e) {
64
            throw new Exception\RuntimeException("Cannot retrieve current schema:" . $e->getMessage());
65
        }
66
        return $schema;
67
    }
68
}
69