Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 96.3% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class HashidsConverterCompilerPass implements CompilerPassInterface |
||
14 | { |
||
15 | 1 | public function process(ContainerBuilder $container) |
|
16 | { |
||
17 | 1 | if (!class_exists(Hashids::class)) { |
|
18 | return; |
||
19 | } |
||
20 | |||
21 | 1 | $this->registerHashidsService($container); |
|
22 | 1 | $this->registerHashidsConverter($container); |
|
23 | 1 | $this->setConverterAsDefault($container); |
|
24 | 1 | } |
|
25 | |||
26 | 1 | protected function registerHashidsService(ContainerBuilder $container): void |
|
27 | { |
||
28 | 1 | $hashidsDefinition = new Definition( |
|
29 | 1 | Hashids::class, |
|
30 | [ |
||
31 | 1 | $container->getParameter('pgs_hash_id.converter.hashids.salt'), |
|
32 | 1 | $container->getParameter('pgs_hash_id.converter.hashids.min_hash_length'), |
|
33 | 1 | $container->getParameter('pgs_hash_id.converter.hashids.alphabet'), |
|
34 | ] |
||
35 | ); |
||
36 | 1 | $hashidsDefinition->setPublic(false); |
|
37 | |||
38 | 1 | $container->addDefinitions(['pgs_hash_id.hashids' => $hashidsDefinition]); |
|
39 | 1 | } |
|
40 | |||
41 | 1 | protected function registerHashidsConverter(ContainerBuilder $container): void |
|
42 | { |
||
43 | 1 | $hashidsConverterDefinition = new Definition( |
|
44 | 1 | HashidsConverter::class, |
|
45 | [ |
||
46 | 1 | new Reference('pgs_hash_id.hashids'), |
|
47 | ] |
||
48 | ); |
||
49 | |||
50 | 1 | $container->addDefinitions(['pgs_hash_id.converter.hashids' => $hashidsConverterDefinition]); |
|
51 | 1 | } |
|
52 | |||
53 | 1 | protected function setConverterAsDefault(ContainerBuilder $container): void |
|
59 | } |
||
60 | 1 | } |
|
61 | } |
||
62 |