Completed
Push — master ( 33f621...f1576d )
by Andreas
27:17
created

datamanagerPass::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 1
rs 10
1
<?php
2
namespace midcom\bundle\dependencyInjection;
3
4
use Symfony\Component\DependencyInjection\ContainerBuilder;
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\Definition;
7
8
class datamanagerPass implements CompilerPassInterface
9
{
10 1
    public function process(ContainerBuilder $container)
11
    {
12 1
        $form_prefix = $this->get_prefix($container->getDefinition('form.factory'));
13
14
        $validator_builder = $container
15 1
            ->getDefinition('validator.builder')
16 1
            ->addMethodCall('addXmlMappings', [[$form_prefix . 'config/validation.xml']]);
17
18 1
        $container->getDefinition('translator')
19 1
            ->addArgument([
20 1
                $this->get_prefix($validator_builder, 'translations/validators.'),
21 1
                $form_prefix . 'translations/validators.'
22
            ]);
23 1
    }
24
25 1
    private static function get_prefix(Definition $service, string $suffix = '') : string
26
    {
27 1
        $rc = new \ReflectionClass($service->getClass());
28 1
        return dirname($rc->getFileName()) . '/Resources/' . $suffix;
29
    }
30
}