Completed
Push — master ( 0ced52...d99b90 )
by Markus
03:30
created

RedisServiceProvider::createRedisClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 13
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jellyfish\Redis;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use Predis\Client;
8
9
class RedisServiceProvider implements ServiceProviderInterface
10
{
11
    /**
12
     * @param \Pimple\Container $pimple
13
     *
14
     * @return void
15
     */
16
    public function register(Container $pimple): void
17
    {
18
        $this->createRedisClient($pimple);
19
    }
20
21
    /**
22
     * @param \Pimple\Container $container
23
     *
24
     * @return \Pimple\ServiceProviderInterface
25
     */
26
    protected function createRedisClient(Container $container): ServiceProviderInterface
27
    {
28
        $config = $container->offsetGet('config');
29
30
        $container->offsetSet('redis_client', function () use ($config) {
31
            return new Client([
32
                'scheme' => 'tcp',
33
                'host' => $config->get(RedisConstants::REDIS_HOST, RedisConstants::DEFAULT_REDIS_HOST),
34
                'port' => $config->get(RedisConstants::REDIS_PORT, RedisConstants::DEFAULT_REDIS_PORT),
35
            ]);
36
        });
37
38
        return $this;
39
    }
40
}
41