ParthenonBundle   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 12
Bugs 0 Features 0
Metric Value
eloc 59
c 12
b 0
f 0
dl 0
loc 107
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handleBillingDoctrine() 0 16 3
A build() 0 68 3
A handleAthenaDoctrine() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2020-2025 Iain Cambridge
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
10
 * the Free Software Foundation, either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
namespace Parthenon;
23
24
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
25
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
26
use Doctrine\DBAL\Types\Type;
27
use Parthenon\AbTesting\Compiler\AbTestingCompilerPass;
28
use Parthenon\Athena\Compiler\AthenaCompilerPass;
29
use Parthenon\Billing\Compiler\BillingCompilerPass;
30
use Parthenon\Common\Compiler\CommonCompilerPass;
31
use Parthenon\Export\Compiler\ExportCompilerPass;
32
use Parthenon\Funnel\Compiler\FunnelCompilerPass;
33
use Parthenon\Health\Compiler\HealthCompilerPass;
34
use Parthenon\MultiTenancy\Compiler\MultiTenancyCompilerPass;
35
use Parthenon\Payments\CompilerPass\SubscriptionsCompilerPass;
36
use Parthenon\User\CompilerPass\UserCompilerPass;
37
use Parthenon\User\Dbal\Types\UtcDateTimeType;
38
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
39
use Symfony\Component\DependencyInjection\ContainerBuilder;
40
use Symfony\Component\HttpKernel\Bundle\Bundle;
41
42
class ParthenonBundle extends Bundle
43
{
44
    public function build(ContainerBuilder $container): void
45
    {
46
        parent::build($container);
47
48
        $mappings = [
49
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Common') => 'Parthenon\Common',
50
        ];
51
52
        $abMappings = [
53
            realpath(__DIR__.'/Resources/config/doctrine-mapping/AbTesting') => 'Parthenon\AbTesting\Entity',
54
        ];
55
56
        $exportMappings = [
57
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Export') => 'Parthenon\Export\Entity',
58
        ];
59
60
        $multiTenacyMappings = [
61
            realpath(__DIR__.'/Resources/config/doctrine-mapping/MultiTenancy') => 'Parthenon\MultiTenancy\Entity',
62
        ];
63
64
        $paymentMappings = [
65
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Payments') => 'Parthenon\Payments\Entity',
66
        ];
67
68
        $userMappings = [
69
            realpath(__DIR__.'/Resources/config/doctrine-mapping/User') => 'Parthenon\User\Entity',
70
        ];
71
72
        $userTeamMappings = [
0 ignored issues
show
Unused Code introduced by
The assignment to $userTeamMappings is dead and can be removed.
Loading history...
73
            realpath(__DIR__.'/Resources/config/doctrine-mapping/UserTeam') => 'Parthenon\User\Entity',
74
        ];
75
76
        $bundles = $container->getParameter('kernel.bundles');
77
78
        if (isset($bundles['DoctrineBundle'])) {
79
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings));
80
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($abMappings, enabledParameter: 'parthenon_abtesting_enabled'));
81
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($exportMappings, enabledParameter: 'parthenon_export_enabled'));
82
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($multiTenacyMappings, ['doctrine.global_entity_manager'], enabledParameter: 'parthenon_multi_tenancy_enabled'));
83
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($paymentMappings, enabledParameter: 'parthenon_payments_enabled'));
84
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($userMappings, enabledParameter: 'parthenon_user_enabled'));
85
86
            Type::overrideType('datetime', UtcDateTimeType::class);
87
            Type::overrideType('datetimetz', UtcDateTimeType::class);
88
        }
89
90
        if (isset($bundles['DoctrineMongoDBBundle'])) {
91
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, ['parthenon.mongodb']));
92
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($abMappings, ['parthenon.ab_testing.mongodb'], enabledParameter: 'parthenon_abtesting_enabled'));
93
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($exportMappings, ['parthenon.export.mongodb'], enabledParameter: 'parthenon_export_enabled'));
94
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($multiTenacyMappings, ['parthenon.multi_tenancy.mongodb'], enabledParameter: 'parthenon_multi_tenancy_enabled'));
95
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($paymentMappings, ['parthenon.payments.mongodb'], enabledParameter: 'parthenon_payments_enabled'));
96
            $container->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($userMappings, ['parthenon.user.mongodb'], enabledParameter: 'parthenon_user_enabled'));
97
        }
98
99
        $container->addCompilerPass(new AbTestingCompilerPass());
100
        $container->addCompilerPass(new AthenaCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
101
        $container->addCompilerPass(new BillingCompilerPass());
102
        $container->addCompilerPass(new CommonCompilerPass());
103
        $container->addCompilerPass(new ExportCompilerPass());
104
        $container->addCompilerPass(new FunnelCompilerPass());
105
        $container->addCompilerPass(new HealthCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
106
        $container->addCompilerPass(new SubscriptionsCompilerPass());
107
        $container->addCompilerPass(new UserCompilerPass());
108
        $container->addCompilerPass(new MultiTenancyCompilerPass());
109
110
        $this->handleAthenaDoctrine($container);
111
        $this->handleBillingDoctrine($container);
112
    }
113
114
    public function handleAthenaDoctrine(ContainerBuilder $containerBuilder): void
115
    {
116
        $athenaMappings = [
117
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Athena') => 'Parthenon\Athena\Entity',
118
        ];
119
120
        // This contains bundles that are loaded
121
        $bundles = $containerBuilder->getParameter('kernel.bundles');
122
123
        // Doctrine ORM Bundle
124
        if (isset($bundles['DoctrineBundle'])) {
125
            $containerBuilder->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($athenaMappings, enabledParameter: 'parthenon_athena_enabled'));
126
        }
127
        // Doctrine ODM Bundle
128
        if (isset($bundles['DoctrineMongoDBBundle'])) {
129
            $containerBuilder->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($athenaMappings, [], enabledParameter: 'parthenon_athena_enabled'));
130
        }
131
    }
132
133
    public function handleBillingDoctrine(ContainerBuilder $containerBuilder): void
134
    {
135
        $mappings = [
136
            realpath(__DIR__.'/Resources/config/doctrine-mapping/Billing') => 'Parthenon\Billing\Entity',
137
        ];
138
139
        // This contains bundles that are loaded
140
        $bundles = $containerBuilder->getParameter('kernel.bundles');
141
142
        // Doctrine ORM Bundle
143
        if (isset($bundles['DoctrineBundle'])) {
144
            $containerBuilder->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings, enabledParameter: 'parthenon_billing_enabled'));
145
        }
146
        // Doctrine ODM Bundle
147
        if (isset($bundles['DoctrineMongoDBBundle'])) {
148
            $containerBuilder->addCompilerPass(DoctrineMongoDBMappingsPass::createXmlMappingDriver($mappings, [], enabledParameter: 'parthenon_billing_enabled'));
149
        }
150
    }
151
}
152