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 Symfony\Component\Config\Definition\Builder\NodeBuilder; |
25
|
|
|
use Symfony\Component\Config\FileLocator; |
26
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
27
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
28
|
|
|
|
29
|
|
|
final class Cloud implements ModuleConfigurationInterface |
30
|
|
|
{ |
31
|
|
|
public function addConfig(NodeBuilder $nodeBuilder): void |
32
|
|
|
{ |
33
|
|
|
$nodeBuilder->arrayNode('cloud') |
34
|
|
|
->children() |
35
|
|
|
->booleanNode('enabled')->defaultFalse()->end() |
36
|
|
|
->arrayNode('digitalocean') |
|
|
|
|
37
|
|
|
->children() |
38
|
|
|
->scalarNode('api_key')->end() |
39
|
|
|
?->end() |
40
|
|
|
->end() |
41
|
|
|
->end(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function handleDefaultParameters(ContainerBuilder $container): void |
45
|
|
|
{ |
46
|
|
|
$container->setParameter('parthenon_cloud_digitalocean_apikey', ''); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function handleConfiguration(array $config, ContainerBuilder $container): void |
50
|
|
|
{ |
51
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config')); |
52
|
|
|
|
53
|
|
|
if (!isset($config['cloud']) || !isset($config['cloud']['enabled']) || false === $config['cloud']['enabled']) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
$loader->load('services/cloud.xml'); |
57
|
|
|
$this->handleDigitalOcean($config, $container); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function handleDigitalOcean(array $config, ContainerBuilder $containerBuilder): void |
61
|
|
|
{ |
62
|
|
|
if (!isset($config['cloud']['digitalocean'])) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$digitalOceanConfig = $config['cloud']['digitalocean']; |
67
|
|
|
|
68
|
|
|
$containerBuilder->setParameter('parthenon_cloud_digitalocean_apikey', $digitalOceanConfig['api_key'] ?? ''); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|