Completed
Push — master ( 01e3cc...866d97 )
by
unknown
122:05 queued 96:28
created

SchemaBuilderInstallerPass::process()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace EzSystems\PlatformInstallerBundle\DependencyInjection\Compiler;
10
11
use EzSystems\DoctrineSchema\API\Builder\SchemaBuilder;
12
use EzSystems\PlatformInstallerBundle\Installer\CoreInstaller;
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
/**
18
 * Enable installer which uses SchemaBuilder.
19
 *
20
 * <code>DoctrineSchemaBundle</code> is available via <code>ezsystems/doctrine-dbal-schema</code> package.
21
 *
22
 * @see \EzSystems\DoctrineSchemaBundle\DoctrineSchemaBundle
23
 * @see \EzSystems\PlatformInstallerBundle\Installer\CoreInstaller
24
 */
25
class SchemaBuilderInstallerPass implements CompilerPassInterface
26
{
27
    const CLEAN_INSTALLER_DEF_ID = 'ezplatform.installer.clean_installer';
28
29
    /**
30
     * Replace Clean installer with CoreInstaller if required SchemaBuilder from DoctrineSchemaBundle is available.
31
     *
32
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
33
     *
34
     * @throws \Exception
35
     */
36
    public function process(ContainerBuilder $container)
37
    {
38
        if (!$container->hasAlias(SchemaBuilder::class)
39
            || !$container->hasDefinition(self::CLEAN_INSTALLER_DEF_ID)
40
        ) {
41
            return;
42
        }
43
44
        $cleanInstallerDefinition = $container->getDefinition(self::CLEAN_INSTALLER_DEF_ID);
45
        $cleanInstallerDefinition->setClass(CoreInstaller::class);
46
        $cleanInstallerDefinition->addArgument(new Reference(SchemaBuilder::class));
47
    }
48
}
49