forked from ezsystems/PlatformUIBundle
/
EzPlatformUIExtension.php
76 lines (65 loc) · 3.13 KB
/
EzPlatformUIExtension.php
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
<?php
/**
* File containing the eZPlatformUIExtension class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\PlatformUIBundle\DependencyInjection;
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ConfigurationProcessor;
use EzSystems\PlatformUIBundle\DependencyInjection\Configuration\PlatformUIMapper;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\Yaml\Yaml;
class EzPlatformUIExtension extends Extension implements PrependExtensionInterface
{
public function getAlias()
{
return 'ez_platformui';
}
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('default_settings.yml');
$processor = new ConfigurationProcessor($container, 'ez_platformui');
$processor->mapConfig($config, new PlatformUIMapper());
}
public function prepend(ContainerBuilder $container)
{
$container->prependExtensionConfig('assetic', ['bundles' => ['eZPlatformUIBundle']]);
$this->prependYui($container);
$this->prependCss($container);
$this->prependImageVariations($container);
}
private function prependYui(ContainerBuilder $container)
{
# Directories where public resources are stored (relative to web/ directory).
$container->setParameter('ez_platformui.public_dir', 'bundles/ezplatformui');
$container->setParameter('ez_platformui.external_assets_public_dir', 'bundles/ezplatformuiassets');
$yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml';
$config = Yaml::parse(file_get_contents($yuiConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($yuiConfigFile));
}
private function prependCss(ContainerBuilder $container)
{
$cssConfigFile = __DIR__ . '/../Resources/config/css.yml';
$config = Yaml::parse(file_get_contents($cssConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($cssConfigFile));
}
private function prependImageVariations(ContainerBuilder $container)
{
$imageConfigFile = __DIR__ . '/../Resources/config/image_variations.yml';
$config = Yaml::parse(file_get_contents($imageConfigFile));
$container->prependExtensionConfig('ezpublish', $config);
$container->addResource(new FileResource($imageConfigFile));
}
}