1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class RepositoryCompilerPass |
18
|
|
|
* |
19
|
|
|
* Repository compiler pass |
20
|
|
|
* |
21
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass |
22
|
|
|
*/ |
23
|
|
|
class RepositoryCompilerPass implements CompilerPassInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
4 |
|
public function process(ContainerBuilder $container) |
29
|
|
|
{ |
30
|
|
|
|
31
|
4 |
|
if (!$container->hasParameter('runopencode.exchange_rate.repository')) { |
32
|
1 |
|
return; |
33
|
|
|
} |
34
|
|
|
|
35
|
3 |
|
$repository = $container->getParameter('runopencode.exchange_rate.repository'); |
36
|
|
|
|
37
|
3 |
|
if ($container->has($repository)) { |
38
|
1 |
|
$container->setAlias('runopencode.exchange_rate.repository', $repository); |
39
|
1 |
|
$container->findDefinition('runopencode.exchange_rate.repository')->setPublic(true); |
40
|
1 |
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
foreach ($container->findTaggedServiceIds('runopencode.exchange_rate.repository') as $id => $tags) { |
44
|
|
|
|
45
|
1 |
|
foreach ($tags as $attributes) { |
46
|
|
|
|
47
|
1 |
|
if (isset($attributes['alias']) && $repository === $attributes['alias']) { |
48
|
1 |
|
$definition = $container->findDefinition($id); |
49
|
1 |
|
$container->setDefinition('runopencode.exchange_rate.repository', $definition); |
50
|
1 |
|
$definition->setPublic(true); |
51
|
1 |
|
return; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
throw new ServiceNotFoundException(sprintf('Repository service "%s" does not exists.', $repository)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|