Skip to content

Commit 31023d0

Browse files
feature #35762 [Asset] Allows to download asset manifest over HTTP (GromNaN)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Asset] Allows to download asset manifest over HTTP | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #35761 Fix #33001 | License | MIT | Doc PR | symfony/symfony-docs#13255 ```yaml framework: assets: json_manifest_path: 'https://cdn.example.com/manifest.json' ``` Commits ------- 4ba12a80e5 [Asset] Allows to download json manifest from a remote url
2 parents 97103c9 + 231d9c2 commit 31023d0

File tree

7 files changed

+25
-4
lines changed

7 files changed

+25
-4
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,12 @@ private function createVersion(ContainerBuilder $container, ?string $version, ?s
10571057
}
10581058

10591059
if (null !== $jsonManifestPath) {
1060-
$def = new ChildDefinition('assets.json_manifest_version_strategy');
1060+
$definitionName = 'assets.json_manifest_version_strategy';
1061+
if (0 === strpos(parse_url($jsonManifestPath, PHP_URL_SCHEME), 'http')) {
1062+
$definitionName = 'assets.remote_json_manifest_version_strategy';
1063+
}
1064+
1065+
$def = new ChildDefinition($definitionName);
10611066
$def->replaceArgument(0, $jsonManifestPath);
10621067
$container->setDefinition('assets._version_'.$name, $def);
10631068

Resources/config/assets.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@
5050
<service id="assets.json_manifest_version_strategy" class="Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy" abstract="true">
5151
<argument /> <!-- manifest path -->
5252
</service>
53+
54+
<service id="assets.remote_json_manifest_version_strategy" class="Symfony\Component\Asset\VersionStrategy\RemoteJsonManifestVersionStrategy" abstract="true">
55+
<argument /> <!-- manifest url -->
56+
<argument type="service" id="http_client" />
57+
</service>
5358
</services>
5459
</container>

Tests/DependencyInjection/Fixtures/php/assets.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
'json_manifest_strategy' => [
2828
'json_manifest_path' => '/path/to/manifest.json',
2929
],
30+
'remote_manifest' => [
31+
'json_manifest_path' => 'https://cdn.example.com/manifest.json',
32+
],
3033
],
3134
],
3235
]);

Tests/DependencyInjection/Fixtures/xml/assets.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<framework:base-url>https://bar_version_strategy.example.com</framework:base-url>
2323
</framework:package>
2424
<framework:package name="json_manifest_strategy" json-manifest-path="/path/to/manifest.json" />
25+
<framework:package name="remote_manifest" json-manifest-path="https://cdn.example.com/manifest.json" />
2526
</framework:assets>
2627
</framework:config>
2728
</container>

Tests/DependencyInjection/Fixtures/yml/assets.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ framework:
1919
version_strategy: assets.custom_version_strategy
2020
json_manifest_strategy:
2121
json_manifest_path: '/path/to/manifest.json'
22+
remote_manifest:
23+
json_manifest_path: 'https://cdn.example.com/manifest.json'

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ public function testAssets()
535535

536536
// packages
537537
$packages = $packages->getArgument(1);
538-
$this->assertCount(6, $packages);
538+
$this->assertCount(7, $packages);
539539

540540
$package = $container->getDefinition((string) $packages['images_path']);
541541
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
@@ -556,6 +556,11 @@ public function testAssets()
556556
$versionStrategy = $container->getDefinition((string) $package->getArgument(1));
557557
$this->assertEquals('assets.json_manifest_version_strategy', $versionStrategy->getParent());
558558
$this->assertEquals('/path/to/manifest.json', $versionStrategy->getArgument(0));
559+
560+
$package = $container->getDefinition($packages['remote_manifest']);
561+
$versionStrategy = $container->getDefinition($package->getArgument(1));
562+
$this->assertSame('assets.remote_json_manifest_version_strategy', $versionStrategy->getParent());
563+
$this->assertSame('https://cdn.example.com/manifest.json', $versionStrategy->getArgument(0));
559564
}
560565

561566
public function testAssetsDefaultVersionStrategyAsService()

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"require-dev": {
3434
"doctrine/annotations": "~1.7",
3535
"doctrine/cache": "~1.0",
36-
"symfony/asset": "^4.4|^5.0",
36+
"symfony/asset": "^5.1",
3737
"symfony/browser-kit": "^4.4|^5.0",
3838
"symfony/console": "^4.4|^5.0",
3939
"symfony/css-selector": "^4.4|^5.0",
@@ -70,7 +70,7 @@
7070
"phpdocumentor/reflection-docblock": "<3.0",
7171
"phpdocumentor/type-resolver": "<0.2.1",
7272
"phpunit/phpunit": "<5.4.3",
73-
"symfony/asset": "<4.4",
73+
"symfony/asset": "<5.1",
7474
"symfony/browser-kit": "<4.4",
7575
"symfony/console": "<4.4",
7676
"symfony/dotenv": "<5.1",

0 commit comments

Comments
 (0)