-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIbexaCloudExtension.php
More file actions
123 lines (102 loc) · 4.06 KB
/
Copy pathIbexaCloudExtension.php
File metadata and controls
123 lines (102 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace Ibexa\Bundle\Cloud\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\Yaml\Yaml;
final class IbexaCloudExtension extends Extension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
);
$loader->load('services.yaml');
if ($this->shouldLoadTestServices($container)) {
$loader->load('test/pages.yaml');
$loader->load('test/components.yaml');
$loader->load('test/contexts.yaml');
}
}
public function prepend(ContainerBuilder $container): void
{
$this->configureUpsunSetup($container);
$this->prependDefaultConfiguration($container);
$this->prependJMSTranslation($container);
}
private function prependDefaultConfiguration(ContainerBuilder $container): void
{
$configFile = __DIR__ . '/../Resources/config/prepend.yaml';
$container->addResource(new FileResource($configFile));
$configs = Yaml::parseFile($configFile, Yaml::PARSE_CONSTANT) ?? [];
foreach ($configs as $name => $config) {
$container->prependExtensionConfig($name, $config);
}
}
private function prependJMSTranslation(ContainerBuilder $container): void
{
$container->prependExtensionConfig('jms_translation', [
'configs' => [
'ibexa_cloud' => [
'dirs' => [
__DIR__ . '/../../',
],
'excluded_dirs' => ['Behat'],
'output_dir' => __DIR__ . '/../Resources/translations/',
'output_format' => 'xliff',
],
],
]);
}
private function shouldLoadTestServices(ContainerBuilder $container): bool
{
return $container->hasParameter('ibexa.behat.browser.enabled')
&& true === $container->getParameter('ibexa.behat.browser.enabled');
}
private function configureUpsunSetup(ContainerBuilder $container): void
{
$envVars = (new UpsunEnvVarLoader())->loadEnvVars();
if (($_SERVER['HTTPCACHE_PURGE_TYPE'] ?? $_ENV['HTTPCACHE_PURGE_TYPE'] ?? null) === 'varnish') {
$container->setParameter('ibexa.http_cache.purge_type', 'varnish');
}
// Cannot be placed as env var due to how LiipImagineBundle processes its config
if (\extension_loaded('imagick')) {
$container->setParameter('liip_imagine_driver', 'imagick');
}
$projectDir = $container->getParameter('kernel.project_dir');
assert(is_string($projectDir));
if (isset($envVars['DFS_NFS_PATH'])) {
$loader = new YamlFileLoader(
$container,
new FileLocator($projectDir . '/config/packages/dfs')
);
$loader->load('dfs.yaml');
}
if (!isset($envVars['CACHE_POOL'])) {
return;
}
$cacheType = $envVars['CACHE_POOL'];
$configFile = match ($cacheType) {
'cache.redis' => 'cache.redis.yaml',
'cache.memcached' => 'cache.memcached.yaml',
default => null,
};
if ($configFile === null) {
return;
}
$loader = new YamlFileLoader(
$container,
new FileLocator($projectDir . '/config/packages/cache_pool')
);
$loader->load($configFile);
}
}