Completed
Pull Request — master (#19)
by Michal
03:25
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 Adminerng\Drivers\Redis;
4
5
use Adminerng\Core\Driver\AbstractDriver;
6
use Adminerng\Core\Exception\ConnectException;
7
use Adminerng\Drivers\Redis\Forms\RedisCredentialsForm;
8
use RedisException;
9
use RedisProxy\RedisProxy;
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 2
            $this->connection->select($credentials['database']);
58 1
        } catch (RedisException $e) {
59
            throw new ConnectException($e->getMessage());
60
        }
61 2
    }
62
63 2
    protected function getFormManager()
64
    {
65 2
        return new RedisFormManager($this->connection);
66
    }
67
68 2
    protected function getHeaderManager()
69
    {
70 2
        return new RedisHeaderManager();
71
    }
72
73 2
    protected function getPermissions()
74
    {
75 2
        return new RedisPermissions();
76
    }
77
78 2
    protected function getDataManager()
79
    {
80 2
        return new RedisDataManager($this->connection);
81
    }
82
}
83