This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\DependencyInjection\Modules; |
||
23 | |||
24 | use Parthenon\Common\Exception\ParameterNotSetException; |
||
25 | use Parthenon\MultiTenancy\Creator\MessengerTenantCreator; |
||
26 | use Parthenon\MultiTenancy\Creator\TenantCreatorInterface; |
||
27 | use Parthenon\MultiTenancy\Database\DatabaseCreatorInterface; |
||
28 | use Parthenon\MultiTenancy\Database\DbalDatabaseCreator; |
||
29 | use Parthenon\MultiTenancy\Database\DigitalOceanDatabaseCreator; |
||
30 | use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
||
31 | use Symfony\Component\Config\FileLocator; |
||
32 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
33 | use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
||
34 | |||
35 | final class MultiTenancy implements ModuleConfigurationInterface |
||
36 | { |
||
37 | public function addConfig(NodeBuilder $nodeBuilder): void |
||
38 | { |
||
39 | $nodeBuilder |
||
40 | ->arrayNode('multi_tenancy') |
||
41 | ->children() |
||
42 | ->booleanNode('enabled')->defaultFalse()->end() |
||
43 | ->booleanNode('background_creation')->defaultFalse()->end() |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
44 | ->scalarNode('domain')->end() |
||
45 | ->scalarNode('domain_format')->end() |
||
46 | ->arrayNode('doctrine') |
||
47 | ->children() |
||
48 | ->scalarNode('dbal_connection')->end() |
||
49 | ->scalarNode('global_dbal_connection')->end() |
||
50 | ->scalarNode('global_orm_entity_manager')->end() |
||
51 | ->scalarNode('orm_entity_manager')->end() |
||
52 | ->scalarNode('default_database')->end() |
||
53 | ->end() |
||
54 | ->end() |
||
55 | ->scalarNode('database_creation_strategy')->end() |
||
56 | ->arrayNode('migrations') |
||
57 | ->children() |
||
58 | ->scalarNode('directory')->end() |
||
59 | ->end() |
||
60 | ->end() |
||
61 | ->arrayNode('digitalocean') |
||
62 | ->children() |
||
63 | ->scalarNode('cluster_id')->end() |
||
64 | ->end() |
||
65 | ->end() |
||
66 | ->end() |
||
67 | ->end(); |
||
68 | } |
||
69 | |||
70 | public function handleDefaultParameters(ContainerBuilder $container): void |
||
71 | { |
||
72 | $container->setParameter('parthenon_multi_tenancy_domain', ''); |
||
73 | $container->setParameter('parthenon_multi_tenancy_domain_format', ''); |
||
74 | $container->setParameter('parthenon_multi_tenancy_migrations_directory', ''); |
||
75 | $container->setParameter('parthenon_multi_tenancy_background_creation', false); |
||
76 | $container->setParameter('parthenon_multi_tenancy_dbal_connection', ''); |
||
77 | $container->setParameter('parthenon_multi_tenancy_global_dbal_connection', ''); |
||
78 | $container->setParameter('parthenon_multi_tenancy_orm_entity_manager', ''); |
||
79 | $container->setParameter('parthenon_multi_tenancy_global_orm_entity_manager', ''); |
||
80 | $container->setParameter('parthenon_multi_tenancy_default_database', 'dummy_database'); |
||
81 | $container->setParameter('parthenon_multi_tenancy_digitalocean_cluster_id', ''); |
||
82 | $container->setParameter('parthenon_multi_tenancy_is_enabled', false); |
||
83 | } |
||
84 | |||
85 | public function handleConfiguration(array $config, ContainerBuilder $container): void |
||
86 | { |
||
87 | if (!isset($config['multi_tenancy']['enabled']) || !$config['multi_tenancy']['enabled']) { |
||
88 | return; |
||
89 | } |
||
90 | $container->setParameter('parthenon_multi_tenancy_enabled', true); |
||
91 | |||
92 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config')); |
||
93 | $loader->load('services/multi_tenancy.xml'); |
||
94 | |||
95 | $this->configureMultiTenancy($config, $container); |
||
96 | |||
97 | $bundles = $container->getParameter('kernel.bundles'); |
||
98 | |||
99 | $bundles = $this->configureDoctrine($bundles, $loader); |
||
100 | |||
101 | $this->configureMongoDb($bundles, $loader); |
||
102 | } |
||
103 | |||
104 | private function configureMultiTenancy(array $config, ContainerBuilder $container): void |
||
105 | { |
||
106 | if (isset($config['multi_tenancy'])) { |
||
107 | $multiTenancyConfig = $config['multi_tenancy']; |
||
108 | $enabled = $multiTenancyConfig['enabled'] ?? false; |
||
109 | $backgroundCreation = $multiTenancyConfig['background_creation'] ?? false; |
||
110 | |||
111 | $container->setParameter('parthenon_multi_tenancy_is_enabled', $enabled); |
||
112 | $container->setParameter('parthenon_multi_tenancy_background_creation', $backgroundCreation); |
||
113 | |||
114 | if (isset($multiTenancyConfig['domain'])) { |
||
115 | $container->setParameter('parthenon_multi_tenancy_domain', $multiTenancyConfig['domain']); |
||
116 | } elseif (!isset($multiTenancyConfig['domain']) && $enabled) { |
||
117 | throw new ParameterNotSetException('parthenon.multi_tenancy.domain must be set when multi_tenancy is enabled'); |
||
118 | } |
||
119 | $container->setParameter('parthenon_multi_tenancy_domain_format', $multiTenancyConfig['domain_format'] ?? $multiTenancyConfig['domain']); |
||
120 | $this->configureMigrations($config, $container); |
||
121 | $this->configureDoctrineConfig($config, $container); |
||
122 | $this->configureTenantCreator($backgroundCreation, $container); |
||
123 | |||
124 | $this->handleDatabaseCreationStrategy($multiTenancyConfig['database_creation_strategy'] ?? 'dbal', $container); |
||
125 | |||
126 | $container->setParameter('parthenon_multi_tenancy_digitalocean_cluster_id', $multiTenancyConfig['digitalocean']['cluster_id'] ?? ''); |
||
127 | } |
||
128 | } |
||
129 | |||
130 | private function configureTenantCreator(bool $creatorBackground, ContainerBuilder $containerBuilder): void |
||
131 | { |
||
132 | if ($creatorBackground) { |
||
133 | $containerBuilder->setAlias(TenantCreatorInterface::class, MessengerTenantCreator::class); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | private function configureMigrations(array $config, ContainerBuilder $containerBuilder): void |
||
138 | { |
||
139 | if (!isset($config['multi_tenancy']['migrations'])) { |
||
140 | return; |
||
141 | } |
||
142 | |||
143 | $containerBuilder->setParameter('parthenon_multi_tenancy_migrations_directory', $config['multi_tenancy']['migrations']['directory'] ?? ''); |
||
144 | } |
||
145 | |||
146 | private function configureDoctrineConfig(array $config, ContainerBuilder $containerBuilder): void |
||
147 | { |
||
148 | if (!isset($config['multi_tenancy']['doctrine'])) { |
||
149 | return; |
||
150 | } |
||
151 | |||
152 | $containerBuilder->setParameter('parthenon_multi_tenancy_global_dbal_connection', $config['multi_tenancy']['doctrine']['global_dbal_connection'] ?? ''); |
||
153 | $containerBuilder->setParameter('parthenon_multi_tenancy_dbal_connection', $config['multi_tenancy']['doctrine']['dbal_connection'] ?? ''); |
||
154 | $containerBuilder->setParameter('parthenon_multi_tenancy_orm_entity_manager', $config['multi_tenancy']['doctrine']['orm_entity_manager'] ?? ''); |
||
155 | $containerBuilder->setParameter('parthenon_multi_tenancy_default_database', $config['multi_tenancy']['doctrine']['default_database'] ?? 'dummy_database'); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @throws \Exception |
||
160 | */ |
||
161 | private function configureDoctrine(float|array|bool|int|string|null $bundles, XmlFileLoader $loader): string|int|bool|array|float|null |
||
162 | { |
||
163 | if (isset($bundles['DoctrineBundle'])) { |
||
164 | $loader->load('services/orm/multi_tenancy.xml'); |
||
165 | } |
||
166 | |||
167 | return $bundles; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | private function configureMongoDb(float|int|bool|array|string|null $bundles, XmlFileLoader $loader): void |
||
174 | { |
||
175 | if (isset($bundles['DoctrineMongoDBBundle'])) { |
||
176 | $loader->load('services/odm/multi_tenancy.xml'); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @throws ParameterNotSetException |
||
182 | */ |
||
183 | private function handleDatabaseCreationStrategy($database_creation_strategy, ContainerBuilder $containerBuilder): void |
||
184 | { |
||
185 | $databaseCreationStrategy = strtolower($database_creation_strategy); |
||
186 | |||
187 | switch ($databaseCreationStrategy) { |
||
188 | case 'dbal': |
||
189 | $id = DbalDatabaseCreator::class; |
||
190 | break; |
||
191 | case 'digitalocean': |
||
192 | $id = DigitalOceanDatabaseCreator::class; |
||
193 | break; |
||
194 | default: |
||
195 | throw new ParameterNotSetException(sprintf("'%s' is not a valid option for multi_tenancy.database_creation_strategy", $databaseCreationStrategy)); |
||
196 | } |
||
197 | |||
198 | $containerBuilder->setAlias(DatabaseCreatorInterface::class, $id); |
||
199 | } |
||
200 | } |
||
201 |