Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit47e4487

Browse files
committed
Option to make asset manifests strict on missing item
1 parent0000dfe commit47e4487

File tree

16 files changed

+202
-115
lines changed

16 files changed

+202
-115
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
677677
->{!class_exists(FullStack::class) &&class_exists(Package::class) ?'canBeDisabled' :'canBeEnabled'}()
678678
->fixXmlConfig('base_url')
679679
->children()
680+
->booleanNode('strict')->defaultFalse()->end()
680681
->scalarNode('version_strategy')->defaultNull()->end()
681682
->scalarNode('version')->defaultNull()->end()
682683
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
@@ -714,6 +715,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
714715
->prototype('array')
715716
->fixXmlConfig('base_url')
716717
->children()
718+
->booleanNode('strict')->defaultFalse()->end()
717719
->scalarNode('version_strategy')->defaultNull()->end()
718720
->scalarNode('version')
719721
->beforeNormalization()

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
10511051
if ($config['version_strategy']) {
10521052
$defaultVersion =newReference($config['version_strategy']);
10531053
}else {
1054-
$defaultVersion =$this->createVersion($container,$config['version'],$config['version_format'],$config['json_manifest_path'],'_default');
1054+
$defaultVersion =$this->createVersion($container,$config['version'],$config['version_format'],$config['json_manifest_path'],'_default',$config['strict']);
10551055
}
10561056

10571057
$defaultPackage =$this->createPackageDefinition($config['base_path'],$config['base_urls'],$defaultVersion);
@@ -1068,7 +1068,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
10681068
// let format fallback to main version_format
10691069
$format =$package['version_format'] ?:$config['version_format'];
10701070
$version =isset($package['version']) ?$package['version'] :null;
1071-
$version =$this->createVersion($container,$version,$format,$package['json_manifest_path'],$name);
1071+
$version =$this->createVersion($container,$version,$format,$package['json_manifest_path'],$name,$package['strict']);
10721072
}
10731073

10741074
$container->setDefinition('assets._package_'.$name,$this->createPackageDefinition($package['base_path'],$package['base_urls'],$version));
@@ -1101,7 +1101,7 @@ private function createPackageDefinition(?string $basePath, array $baseUrls, Ref
11011101
return$package;
11021102
}
11031103

1104-
privatefunctioncreateVersion(ContainerBuilder$container, ?string$version, ?string$format, ?string$jsonManifestPath,string$name):Reference
1104+
privatefunctioncreateVersion(ContainerBuilder$container, ?string$version, ?string$format, ?string$jsonManifestPath,string$name,bool$strict):Reference
11051105
{
11061106
// Configuration prevents $version and $jsonManifestPath from being set
11071107
if (null !==$version) {
@@ -1117,12 +1117,15 @@ private function createVersion(ContainerBuilder $container, ?string $version, ?s
11171117

11181118
if (null !==$jsonManifestPath) {
11191119
$definitionName ='assets.json_manifest_version_strategy';
1120+
$strictArg =1;
11201121
if (0 ===strpos(parse_url($jsonManifestPath, \PHP_URL_SCHEME),'http')) {
11211122
$definitionName ='assets.remote_json_manifest_version_strategy';
1123+
$strictArg =2;
11221124
}
11231125

11241126
$def =newChildDefinition($definitionName);
11251127
$def->replaceArgument(0,$jsonManifestPath);
1128+
$def->replaceArgument($strictArg,$strict);
11261129
$container->setDefinition('assets._version_'.$name,$def);
11271130

11281131
returnnewReference('assets._version_'.$name);

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

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

8283
->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class)
8384
->abstract()
8485
->args([
8586
abstract_arg('manifest url'),
8687
service('http_client'),
88+
false,
8789
])
8890
;
8991
};

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<xsd:attributename="version"type="xsd:string" />
152152
<xsd:attributename="version-format"type="xsd:string" />
153153
<xsd:attributename="json-manifest-path"type="xsd:string" />
154+
<xsd:attributename="strict"type="xsd:boolean" />
154155
</xsd:complexType>
155156

156157
<xsd:complexTypename="package">
@@ -164,6 +165,7 @@
164165
<xsd:attributename="version"type="xsd:string" />
165166
<xsd:attributename="version-format"type="xsd:string" />
166167
<xsd:attributename="json-manifest-path"type="xsd:string" />
168+
<xsd:attributename="strict"type="xsd:boolean" />
167169
</xsd:complexType>
168170

169171
<xsd:complexTypename="translator">

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function testAssetsCanBeEnabled()
8383
'base_urls' => [],
8484
'packages' => [],
8585
'json_manifest_path' =>null,
86+
'strict' =>false,
8687
];
8788

8889
$this->assertEquals($defaultConfig,$config['assets']);
@@ -454,6 +455,7 @@ protected static function getBundleDefaultConfig()
454455
'base_urls' => [],
455456
'packages' => [],
456457
'json_manifest_path' =>null,
458+
'strict' =>false,
457459
],
458460
'cache' => [
459461
'pools' => [],

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
'remote_manifest' => [
3131
'json_manifest_path' =>'https://cdn.example.com/manifest.json',
3232
],
33+
'strict_manifest_strategy' => [
34+
'json_manifest_path' =>'/path/to/manifest.json',
35+
'strict' =>true,
36+
],
37+
'strict_remote_manifest' => [
38+
'json_manifest_path' =>'https://cdn.example.com/manifest.json',
39+
'strict' =>true,
40+
],
3341
],
3442
],
3543
]);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
</framework:package>
2424
<framework:packagename="json_manifest_strategy"json-manifest-path="/path/to/manifest.json" />
2525
<framework:packagename="remote_manifest"json-manifest-path="https://cdn.example.com/manifest.json" />
26+
<framework:packagename="strict_manifest_strategy"json-manifest-path="/path/to/manifest.json"strict="true" />
27+
<framework:packagename="strict_remote_manifest"json-manifest-path="https://cdn.example.com/manifest.json"strict="true" />
2628
</framework:assets>
2729
</framework:config>
2830
</container>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ framework:
2121
json_manifest_path:'/path/to/manifest.json'
2222
remote_manifest:
2323
json_manifest_path:'https://cdn.example.com/manifest.json'
24+
strict_manifest_strategy:
25+
json_manifest_path:'/path/to/manifest.json'
26+
strict:true
27+
strict_remote_manifest:
28+
json_manifest_path:'https://cdn.example.com/manifest.json'
29+
strict:true

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ public function testAssets()
579579

580580
// packages
581581
$packages =$packages->getArgument(1);
582-
$this->assertCount(7,$packages);
582+
$this->assertCount(9,$packages);
583583

584584
$package =$container->getDefinition((string)$packages['images_path']);
585585
$this->assertPathPackage($container,$package,'/foo','SomeVersionScheme','%%s?version=%%s');
@@ -600,11 +600,25 @@ public function testAssets()
600600
$versionStrategy =$container->getDefinition((string)$package->getArgument(1));
601601
$this->assertEquals('assets.json_manifest_version_strategy',$versionStrategy->getParent());
602602
$this->assertEquals('/path/to/manifest.json',$versionStrategy->getArgument(0));
603+
$this->assertFalse($versionStrategy->getArgument(1));
603604

604605
$package =$container->getDefinition($packages['remote_manifest']);
605606
$versionStrategy =$container->getDefinition($package->getArgument(1));
606607
$this->assertSame('assets.remote_json_manifest_version_strategy',$versionStrategy->getParent());
607608
$this->assertSame('https://cdn.example.com/manifest.json',$versionStrategy->getArgument(0));
609+
$this->assertFalse($versionStrategy->getArgument(2));
610+
611+
$package =$container->getDefinition((string)$packages['strict_manifest_strategy']);
612+
$versionStrategy =$container->getDefinition((string)$package->getArgument(1));
613+
$this->assertEquals('assets.json_manifest_version_strategy',$versionStrategy->getParent());
614+
$this->assertEquals('/path/to/manifest.json',$versionStrategy->getArgument(0));
615+
$this->assertTrue($versionStrategy->getArgument(1));
616+
617+
$package =$container->getDefinition($packages['strict_remote_manifest']);
618+
$versionStrategy =$container->getDefinition($package->getArgument(1));
619+
$this->assertSame('assets.remote_json_manifest_version_strategy',$versionStrategy->getParent());
620+
$this->assertSame('https://cdn.example.com/manifest.json',$versionStrategy->getArgument(0));
621+
$this->assertTrue($versionStrategy->getArgument(2));
608622
}
609623

610624
publicfunctiontestAssetsDefaultVersionStrategyAsService()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
namespaceSymfony\Component\Asset\Exception;
13+
14+
/**
15+
* Base RuntimeException for the Asset component.
16+
*
17+
* @author Fabien Potencier <fabien@symfony.com>
18+
*/
19+
class RuntimeExceptionextends \RuntimeExceptionimplements ExceptionInterface
20+
{
21+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp