Completed
Push — master ( d1a8ba...6150c3 )
by Daniel
12s queued 10s
created

createLockIdentifierGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Jellyfish\LockSymfony;
4
5
use Jellyfish\Lock\LockIdentifierGeneratorInterface;
6
use Pimple\Container;
7
use Pimple\ServiceProviderInterface;
8
use Symfony\Component\Lock\Factory as SymfonyLockFactory;
9
use Symfony\Component\Lock\Store\RedisStore;
10
11
class LockSymfonyServiceProvider implements ServiceProviderInterface
12
{
13
    /**
14
     * @param \Pimple\Container $pimple
15
     *
16
     * @return void
17
     */
18
    public function register(Container $pimple): void
19
    {
20
        $this->createLockFactory($pimple);
21
    }
22
23
    /**
24
     * @param \Pimple\Container $container
25
     *
26
     * @return \Pimple\ServiceProviderInterface
27
     */
28
    protected function createLockFactory(Container $container): ServiceProviderInterface
29
    {
30
        $self = $this;
31
32
        $container->offsetSet('lock_factory', function (Container $container) use ($self) {
33
            return new LockFactory(
34
                $self->createSymfonyLockFactory($container),
35
                $self->createLockIdentifierGenerator()
36
            );
37
        });
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param \Pimple\Container $container
44
     *
45
     * @return \Symfony\Component\Lock\Factory
46
     */
47
    protected function createSymfonyLockFactory(Container $container): SymfonyLockFactory
48
    {
49
        $redisStore = new RedisStore($container->offsetGet('redis_client'));
50
51
        return new SymfonyLockFactory($redisStore);
52
    }
53
54
    /**
55
     * @return \Jellyfish\Lock\LockIdentifierGeneratorInterface
56
     */
57
    protected function createLockIdentifierGenerator(): LockIdentifierGeneratorInterface
58
    {
59
        return new LockIdentifierGenerator();
60
    }
61
}
62