Total Complexity | 4 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 |
||
60 | } |
||
61 | } |
||
62 |