DoctrineORMCustomTypesPass::process()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 35
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 24
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
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\CMSKernel\Infrastructure\Symfony\Bundle\DependencyInjection\Compiler;
13
14
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Menu\Types\MenuIdType;
15
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Menu\Types\MenuItemIdType;
16
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Menu\Types\MenuTranslationIdType;
17
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Page\Template\Types\TemplateIdType;
18
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Page\Types\PageIdType;
19
use LIN3S\CMSKernel\Infrastructure\Persistence\Doctrine\DBAL\Page\Types\PageTranslationIdType;
20
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
23
/**
24
 * @author Beñat Espiña <[email protected]>
25
 */
26
class DoctrineORMCustomTypesPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container)
32
    {
33
        $customTypes = $container->getParameter('doctrine.dbal.connection_factory.types');
34
        $customTypes = array_merge($customTypes, [
35
            'menu_id'             => [
36
                'class'     => MenuIdType::class,
37
                'commented' => true,
38
            ],
39
            'menu_item_id'        => [
40
                'class'     => MenuItemIdType::class,
41
                'commented' => true,
42
            ],
43
            'menu_translation_id' => [
44
                'class'     => MenuTranslationIdType::class,
45
                'commented' => true,
46
            ],
47
            'page_id'             => [
48
                'class'     => PageIdType::class,
49
                'commented' => true,
50
            ],
51
            'page_translation_id' => [
52
                'class'     => PageTranslationIdType::class,
53
                'commented' => true,
54
            ],
55
            'template_id'             => [
56
                'class'     => TemplateIdType::class,
57
                'commented' => true,
58
            ],
59
        ]);
60
61
        $container->setParameter('doctrine.dbal.connection_factory.types', $customTypes);
62
        $container->findDefinition('doctrine.dbal.connection_factory')->replaceArgument(
63
            0, '%doctrine.dbal.connection_factory.types%'
64
        );
65
    }
66
}
67