Skip to content

Commit a227377

Browse files
committed
feature symfony#251 Move Symfony DI config from XML to PHP (dmaicher)
This PR was merged into the 2.x branch. Discussion ---------- Move Symfony DI config from XML to PHP Fixes symfony#250 Commits ------- fc53946 Move Symfony DI config from XML to PHP
2 parents 5dbd55e + fc53946 commit a227377

File tree

4 files changed

+101
-76
lines changed

4 files changed

+101
-76
lines changed

src/DependencyInjection/WebpackEncoreExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Definition;
19-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
2020
use Symfony\Component\DependencyInjection\Reference;
2121
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2222
use Symfony\Component\WebLink\EventListener\AddLinkHeaderListener;
@@ -30,8 +30,8 @@ final class WebpackEncoreExtension extends Extension
3030

3131
public function load(array $configs, ContainerBuilder $container): void
3232
{
33-
$loader = new XmlFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
34-
$loader->load('services.xml');
33+
$loader = new PhpFileLoader($container, new FileLocator(\dirname(__DIR__).'/Resources/config'));
34+
$loader->load('services.php');
3535

3636
$configuration = $this->getConfiguration($configs, $container);
3737
$config = $this->processConfiguration($configuration, $configs);

src/Resources/config/services.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Symfony WebpackEncoreBundle package.
7+
*
8+
* (c) Fabien Potencier <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
15+
16+
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
17+
use Symfony\Component\DependencyInjection\ServiceLocator;
18+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection;
19+
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface;
20+
use Symfony\WebpackEncoreBundle\Asset\TagRenderer;
21+
use Symfony\WebpackEncoreBundle\CacheWarmer\EntrypointCacheWarmer;
22+
use Symfony\WebpackEncoreBundle\EventListener\ExceptionListener;
23+
use Symfony\WebpackEncoreBundle\EventListener\PreLoadAssetsEventListener;
24+
use Symfony\WebpackEncoreBundle\EventListener\ResetAssetsEventListener;
25+
use Symfony\WebpackEncoreBundle\Twig\EntryFilesTwigExtension;
26+
27+
return static function (ContainerConfigurator $containerConfigurator): void {
28+
$containerConfigurator->services()
29+
->set('webpack_encore.entrypoint_lookup_collection', EntrypointLookupCollection::class)
30+
->args([
31+
abstract_arg('build list of entrypoints locator'),
32+
])
33+
34+
->alias(EntrypointLookupCollectionInterface::class, 'webpack_encore.entrypoint_lookup_collection')
35+
36+
->set('webpack_encore.tag_renderer', TagRenderer::class)
37+
->tag('kernel.reset', ['method' => 'reset'])
38+
->args([
39+
service('webpack_encore.entrypoint_lookup_collection'),
40+
service('assets.packages'),
41+
[], // Default attributes
42+
[], // Default script attributes
43+
[], // Default link attributes
44+
service('event_dispatcher'),
45+
])
46+
47+
->set('webpack_encore.twig_entry_files_extension', EntryFilesTwigExtension::class)
48+
->tag('twig.extension')
49+
->args([
50+
inline_service(ServiceLocator::class)
51+
->tag('container.service_locator')
52+
->args([
53+
[
54+
'webpack_encore.entrypoint_lookup_collection' => service('webpack_encore.entrypoint_lookup_collection'),
55+
'webpack_encore.tag_renderer' => service('webpack_encore.tag_renderer'),
56+
],
57+
]),
58+
])
59+
60+
->set('webpack_encore.entrypoint_lookup.cache_warmer', EntrypointCacheWarmer::class)
61+
->tag('kernel.cache_warmer')
62+
->args([
63+
abstract_arg(' build list of entrypoint paths'),
64+
service('http_client')->nullOnInvalid(),
65+
'%kernel.build_dir%/webpack_encore.cache.php',
66+
])
67+
68+
->set('webpack_encore.cache', PhpArrayAdapter::class)
69+
->factory([PhpArrayAdapter::class, 'create'])
70+
->args([
71+
'%kernel.build_dir%/webpack_encore.cache.php',
72+
service('cache.webpack_encore'),
73+
])
74+
75+
->set('cache.webpack_encore')
76+
->parent('cache.system')
77+
->tag('cache.pool')
78+
79+
->set('webpack_encore.exception_listener', ExceptionListener::class)
80+
->tag('kernel.event_listener', ['event' => 'kernel.exception'])
81+
->args([
82+
service('webpack_encore.entrypoint_lookup_collection'),
83+
abstract_arg('build list of build names'),
84+
])
85+
86+
->set('webpack_encore.preload_assets_event_listener', PreLoadAssetsEventListener::class)
87+
->tag('kernel.event_subscriber')
88+
->args([
89+
service('webpack_encore.tag_renderer'),
90+
])
91+
92+
->set(ResetAssetsEventListener::class)
93+
->tag('kernel.event_subscriber')
94+
->args([
95+
service('webpack_encore.entrypoint_lookup_collection'),
96+
])
97+
;
98+
};

src/Resources/config/services.xml

Lines changed: 0 additions & 72 deletions
This file was deleted.

tests/IntegrationTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
328328
__DIR__.'/fixtures' => 'integration_test',
329329
],
330330
'strict_variables' => true,
331-
'exception_controller' => null,
332331
]);
333332

334333
$container->loadFromExtension('webpack_encore', [

0 commit comments

Comments
 (0)