Skip to content

Commit c766e59

Browse files
committed
feature #39484 [FrameworkBundle] Allow env variables in json_manifest_path (jderusse)
This PR was merged into the 5.3-dev branch. Discussion ---------- [FrameworkBundle] Allow env variables in `json_manifest_path` | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | Fix #39264 | License | MIT | Doc PR | - the parameter `framework.assets.json_manifest_path` does not allow env variable when value is remote. This PR adds a new `DynamicJsonManifestVersionStrategy` to fix that. Commits ------- 4e4a81c Allow env variables in `json_manifest_path`
2 parents c8c7fd5 + 4e4a81c commit c766e59

File tree

15 files changed

+138
-33
lines changed

15 files changed

+138
-33
lines changed

UPGRADE-5.3.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 5.2 to 5.3
22
=======================
33

4+
Asset
5+
-----
6+
7+
* Deprecated `RemoteJsonManifestVersionStrategy`, use `JsonManifestVersionStrategy` instead.
8+
49
Form
510
----
611

UPGRADE-6.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 5.x to 6.0
22
=======================
33

4+
Asset
5+
-----
6+
7+
* Removed `RemoteJsonManifestVersionStrategy`, use `JsonManifestVersionStrategy` instead.
8+
49
Config
510
------
611

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,12 +1129,7 @@ private function createVersion(ContainerBuilder $container, ?string $version, ?s
11291129
}
11301130

11311131
if (null !== $jsonManifestPath) {
1132-
$definitionName = 'assets.json_manifest_version_strategy';
1133-
if (0 === strpos(parse_url($jsonManifestPath, \PHP_URL_SCHEME), 'http')) {
1134-
$definitionName = 'assets.remote_json_manifest_version_strategy';
1135-
}
1136-
1137-
$def = new ChildDefinition($definitionName);
1132+
$def = new ChildDefinition('assets.json_manifest_version_strategy');
11381133
$def->replaceArgument(0, $jsonManifestPath);
11391134
$container->setDefinition('assets._version_'.$name, $def);
11401135

src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@
7777
->abstract()
7878
->args([
7979
abstract_arg('manifest path'),
80+
service('http_client'),
8081
])
8182

8283
->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class)
8384
->abstract()
85+
->deprecate('symfony/framework-bundle', '5.3', 'The "%service_id%" service is deprecated, use "assets.json_manifest_version_strategy" instead.')
8486
->args([
8587
abstract_arg('manifest url'),
8688
service('http_client'),

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@
3030
'remote_manifest' => [
3131
'json_manifest_path' => 'https://cdn.example.com/manifest.json',
3232
],
33+
'var_manifest' => [
34+
'json_manifest_path' => '%var_json_manifest_path%',
35+
],
36+
'env_manifest' => [
37+
'json_manifest_path' => '%env(env_manifest)%',
38+
],
3339
],
3440
],
3541
]);
42+
43+
$container->setParameter('var_json_manifest_path', 'https://cdn.example.com/manifest.json');
44+
$container->setParameter('env(env_manifest)', 'https://cdn.example.com/manifest.json');

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
</framework:package>
2424
<framework:package name="json_manifest_strategy" json-manifest-path="/path/to/manifest.json" />
2525
<framework:package name="remote_manifest" json-manifest-path="https://cdn.example.com/manifest.json" />
26+
<framework:package name="var_manifest" json-manifest-path="%var_json_manifest_path%" />
27+
<framework:package name="env_manifest" json-manifest-path="%env(env_manifest)%" />
2628
</framework:assets>
2729
</framework:config>
30+
31+
<parameters>
32+
<parameter key="var_json_manifest_path">https://cdn.example.com/manifest.json</parameter>
33+
<parameter key="env(env_manifest)">https://cdn.example.com/manifest.json</parameter>
34+
</parameters>
2835
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ framework:
2121
json_manifest_path: '/path/to/manifest.json'
2222
remote_manifest:
2323
json_manifest_path: 'https://cdn.example.com/manifest.json'
24+
var_manifest:
25+
json_manifest_path: '%var_json_manifest_path%'
26+
env_manifest:
27+
json_manifest_path: '%env(env_manifest)%'
28+
29+
parameters:
30+
var_json_manifest_path: 'https://cdn.example.com/manifest.json'
31+
env(env_manifest): https://cdn.example.com/manifest.json

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public function testAssets()
597597

598598
// packages
599599
$packages = $packages->getArgument(1);
600-
$this->assertCount(7, $packages);
600+
$this->assertCount(9, $packages);
601601

602602
$package = $container->getDefinition((string) $packages['images_path']);
603603
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
@@ -621,8 +621,18 @@ public function testAssets()
621621

622622
$package = $container->getDefinition($packages['remote_manifest']);
623623
$versionStrategy = $container->getDefinition($package->getArgument(1));
624-
$this->assertSame('assets.remote_json_manifest_version_strategy', $versionStrategy->getParent());
624+
$this->assertSame('assets.json_manifest_version_strategy', $versionStrategy->getParent());
625625
$this->assertSame('https://cdn.example.com/manifest.json', $versionStrategy->getArgument(0));
626+
627+
$package = $container->getDefinition($packages['var_manifest']);
628+
$versionStrategy = $container->getDefinition($package->getArgument(1));
629+
$this->assertSame('assets.json_manifest_version_strategy', $versionStrategy->getParent());
630+
$this->assertSame('https://cdn.example.com/manifest.json', $versionStrategy->getArgument(0));
631+
632+
$package = $container->getDefinition($packages['env_manifest']);
633+
$versionStrategy = $container->getDefinition($package->getArgument(1));
634+
$this->assertSame('assets.json_manifest_version_strategy', $versionStrategy->getParent());
635+
$this->assertStringMatchesFormat('env_%s', $versionStrategy->getArgument(0));
626636
}
627637

628638
public function testAssetsDefaultVersionStrategyAsService()

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"require-dev": {
3535
"doctrine/annotations": "~1.7",
3636
"doctrine/cache": "~1.0",
37-
"symfony/asset": "^5.1",
37+
"symfony/asset": "^5.3",
3838
"symfony/browser-kit": "^4.4|^5.0",
3939
"symfony/console": "^5.2",
4040
"symfony/css-selector": "^4.4|^5.0",
@@ -71,7 +71,7 @@
7171
"phpdocumentor/reflection-docblock": "<3.0",
7272
"phpdocumentor/type-resolver": "<0.2.1",
7373
"phpunit/phpunit": "<5.4.3",
74-
"symfony/asset": "<5.1",
74+
"symfony/asset": "<5.3",
7575
"symfony/browser-kit": "<4.4",
7676
"symfony/console": "<5.2",
7777
"symfony/dotenv": "<5.1",

src/Symfony/Component/Asset/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* deprecated `RemoteJsonManifestVersionStrategy`, use `JsonManifestVersionStrategy` instead.
8+
49
5.1.0
510
-----
611

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy