Completed
Push — master ( 6d1120...3e38c4 )
by Michal
10s
created

RedisDriver::getDataManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace UniMan\Drivers\Redis;
4
5
use RedisException;
6
use RedisProxy\RedisProxy;
7
use UniMan\Core\Driver\AbstractDriver;
8
use UniMan\Core\Exception\ConnectException;
9
use UniMan\Drivers\Redis\Forms\RedisCredentialsForm;
10
11
class RedisDriver extends AbstractDriver
12
{
13
    const TYPE_KEY = 'key';
14
    const TYPE_HASH = 'hash';
15
    const TYPE_SET = 'set';
16
17
    private $connection;
18
19 2
    public function check()
20
    {
21 2
        return extension_loaded('redis') || class_exists('Predis\Client');
22
    }
23
24 2
    public function extensions()
25
    {
26 2
        return ['redis'];
27
    }
28
29 2
    public function classes()
30
    {
31 2
        return ['Predis\Client'];
32
    }
33
34 2
    public function type()
35
    {
36 2
        return 'redis';
37
    }
38
39 2
    public function defaultCredentials()
40
    {
41
        return [
42 2
            'host' => 'localhost',
43 1
            'port' => '6379',
44 1
            'database' => '0',
45 1
        ];
46
    }
47
48 2
    public function getCredentialsForm()
49
    {
50 2
        return new RedisCredentialsForm();
51
    }
52
53 2
    public function connect(array $credentials)
54
    {
55
        try {
56 2
            $this->connection = new RedisProxy($credentials['host'], $credentials['port'], $credentials['database']);
57 1
        } catch (RedisException $e) {
58
            throw new ConnectException($e->getMessage());
59
        }
60 2
    }
61
62 2
    protected function getFormManager()
63
    {
64 2
        return new RedisFormManager($this->connection);
65
    }
66
67 2
    protected function getHeaderManager()
68
    {
69 2
        return new RedisHeaderManager();
70
    }
71
72 2
    protected function getPermissions()
73
    {
74 2
        return new RedisPermissions();
75
    }
76
77 2
    protected function getDataManager()
78
    {
79 2
        return new RedisDataManager($this->connection);
80
    }
81
}
82