|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\DependencyInjection\Compiler; |
|
|
13 |
|
|
|
14 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
15 |
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; |
|
|
16 |
|
|
|
17 |
/** |
|
|
18 |
* Resolves all parameter placeholders "%somevalue%" to their real values. |
|
|
19 |
* |
|
|
20 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
21 |
*/ |
|
|
22 |
class ResolveParameterPlaceHoldersPass implements CompilerPassInterface |
|
|
23 |
{ |
|
|
24 |
private $parameterBag; |
|
|
25 |
|
|
|
26 |
/** |
|
|
27 |
* Processes the ContainerBuilder to resolve parameter placeholders. |
|
|
28 |
* |
|
|
29 |
* @param ContainerBuilder $container |
|
|
30 |
*/ |
|
|
31 |
public function process(ContainerBuilder $container) |
|
|
32 |
{ |
|
|
33 |
$parameterBag = $container->getParameterBag(); |
|
|
34 |
|
|
|
35 |
foreach ($container->getDefinitions() as $id => $definition) { |
|
|
36 |
try { |
|
|
37 |
$definition->setClass($parameterBag->resolveValue($definition->getClass())); |
|
|
38 |
$definition->setFile($parameterBag->resolveValue($definition->getFile())); |
|
|
39 |
$definition->setArguments($parameterBag->resolveValue($definition->getArguments())); |
|
|
40 |
|
|
|
41 |
$calls = array(); |
|
|
42 |
foreach ($definition->getMethodCalls() as $name => $arguments) { |
|
|
43 |
$calls[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($arguments); |
|
|
44 |
} |
|
|
45 |
$definition->setMethodCalls($calls); |
|
|
46 |
|
|
|
47 |
$definition->setProperties($parameterBag->resolveValue($definition->getProperties())); |
|
|
48 |
} catch (ParameterNotFoundException $e) { |
|
|
49 |
$e->setSourceId($id); |
|
|
50 |
|
|
|
51 |
throw $e; |
|
|
52 |
} |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
$aliases = array(); |
|
|
56 |
foreach ($container->getAliases() as $name => $target) { |
|
|
57 |
$aliases[$parameterBag->resolveValue($name)] = $parameterBag->resolveValue($target); |
|
|
58 |
} |
|
|
59 |
$container->setAliases($aliases); |
|
|
60 |
|
|
|
61 |
$parameterBag->resolve(); |
|
|
62 |
} |
|
|
63 |
} |