Completed
Push — master ( 73f017...763f53 )
by Beñat
02:15
created

DoctrineORMCustomTypesPass::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
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 LIN3S\SharedKernel\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler;
13
14
use LIN3S\SharedKernel\Infrastructure\Persistence\Doctrine\ORM\Phone\Types\PhoneType;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class DoctrineORMCustomTypesPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        $customTypes = $container->getParameter('doctrine.dbal.connection_factory.types');
29
        $customTypes = array_merge($customTypes, [
30
            'phone' => [
31
                'class'     => PhoneType::class,
32
                'commented' => true,
33
            ],
34
        ]);
35
36
        $container->setParameter('doctrine.dbal.connection_factory.types', $customTypes);
37
        $container->findDefinition('doctrine.dbal.connection_factory')->replaceArgument(
38
            0, '%doctrine.dbal.connection_factory.types%'
39
        );
40
    }
41
}
42