Skip to content

Commit f6be9cd

Browse files
NguyenTruongLinhTobion
authored andcommitted
[AssetBundle] Move xml service configuration to php
1 parent a6b1691 commit f6be9cd

File tree

3 files changed

+92
-62
lines changed

3 files changed

+92
-62
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function load(array $configs, ContainerBuilder $container)
315315
throw new LogicException('Asset support cannot be enabled as the Asset component is not installed. Try running "composer require symfony/asset".');
316316
}
317317

318-
$this->registerAssetsConfiguration($config['assets'], $container, $loader);
318+
$this->registerAssetsConfiguration($config['assets'], $container, $phpLoader);
319319
}
320320

321321
if ($this->messengerConfigEnabled = $this->isConfigEnabled($container, $config['messenger'])) {
@@ -990,9 +990,9 @@ private function registerRequestConfiguration(array $config, ContainerBuilder $c
990990
}
991991
}
992992

993-
private function registerAssetsConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
993+
private function registerAssetsConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader)
994994
{
995-
$loader->load('assets.xml');
995+
$loader->load('assets.php');
996996

997997
if ($config['version_strategy']) {
998998
$defaultVersion = new Reference($config['version_strategy']);

Resources/config/assets.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\Asset\Context\RequestStackContext;
15+
use Symfony\Component\Asset\Package;
16+
use Symfony\Component\Asset\Packages;
17+
use Symfony\Component\Asset\PathPackage;
18+
use Symfony\Component\Asset\UrlPackage;
19+
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
20+
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
21+
use Symfony\Component\Asset\VersionStrategy\RemoteJsonManifestVersionStrategy;
22+
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
23+
24+
return static function (ContainerConfigurator $container) {
25+
$container->parameters()
26+
->set('asset.request_context.base_path', null)
27+
->set('asset.request_context.secure', null)
28+
;
29+
30+
$container->services()
31+
->set('assets.packages', Packages::class)
32+
->args([
33+
service('assets.empty_package'),
34+
[],
35+
])
36+
37+
->alias(Packages::class, 'assets.packages')
38+
39+
->set('assets.empty_package', Package::class)
40+
->args([
41+
service('assets.empty_version_strategy'),
42+
])
43+
44+
->set('assets.context', RequestStackContext::class)
45+
->args([
46+
service('request_stack'),
47+
param('asset.request_context.base_path'),
48+
param('asset.request_context.secure'),
49+
])
50+
51+
->set('assets.path_package', PathPackage::class)
52+
->abstract()
53+
->args([
54+
abstract_arg('base path'),
55+
abstract_arg('version strategy'),
56+
service('assets.context'),
57+
])
58+
59+
->set('assets.url_package', UrlPackage::class)
60+
->abstract()
61+
->args([
62+
abstract_arg('base URLs'),
63+
abstract_arg('version strategy'),
64+
service('assets.context'),
65+
])
66+
67+
->set('assets.static_version_strategy', StaticVersionStrategy::class)
68+
->abstract()
69+
->args([
70+
abstract_arg('version'),
71+
abstract_arg('format'),
72+
])
73+
74+
->set('assets.empty_version_strategy', EmptyVersionStrategy::class)
75+
76+
->set('assets.json_manifest_version_strategy', JsonManifestVersionStrategy::class)
77+
->abstract()
78+
->args([
79+
abstract_arg('manifest path'),
80+
])
81+
82+
->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class)
83+
->abstract()
84+
->args([
85+
abstract_arg('manifest url'),
86+
service('http_client'),
87+
])
88+
;
89+
};

Resources/config/assets.xml

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

0 commit comments

Comments
 (0)