/
FormPass.php
50 lines (40 loc) · 1.59 KB
/
FormPass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/**
* Adds all services with the tags "form.type" and "form.type_guesser" as
* arguments of the "form.extension" service
*
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
*/
class FormPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('form.extension')) {
return;
}
// Builds an array with service IDs as keys and tag aliases as values
$types = array();
foreach ($container->findTaggedServiceIds('form.type') as $serviceId => $tag) {
$alias = isset($tag[0]['alias'])
? $tag[0]['alias']
: $serviceId;
// Flip, because we want tag aliases (= type identifiers) as keys
$types[$alias] = $serviceId;
}
$container->getDefinition('form.extension')->replaceArgument(1, $types);
// Find all services annotated with "form.type_guesser"
$guessers = array_keys($container->findTaggedServiceIds('form.type_guesser'));
$container->getDefinition('form.extension')->replaceArgument(2, $guessers);
}
}