-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
WebpackEncoreExtension.php
52 lines (44 loc) · 2.22 KB
/
WebpackEncoreExtension.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
<?php
/*
* This file is part of the Symfony WebpackEncoreBundle package.
* (c) Fabien Potencier <fabien@symfony.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\WebpackEncoreBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup;
final class WebpackEncoreExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
$loader->load('services.xml');
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
$factories = [
'_default' => new Reference($this->entrypointFactory($container, '_default', $config['output_path']))
];
foreach ($config['builds'] as $name => $path) {
$factories[$name] = new Reference($this->entrypointFactory($container, $name, $path));
};
$container->getDefinition('webpack_encore.entrypoint_lookup')
->replaceArgument(0, $factories['_default']);
$container->getDefinition('webpack_encore.entrypoint_lookup_collection')
->replaceArgument(0, ServiceLocatorTagPass::register($container, $factories));
$container->getDefinition('webpack_encore.tag_renderer')
->replaceArgument(2, $config['integrity_hashes']);
}
private function entrypointFactory(ContainerBuilder $container, string $name, string $path): string
{
$id = sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
$container->setDefinition($id, new Definition(EntrypointLookup::class, [$path.'/entrypoints.json']));
return $id;
}
}