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

Appearance settings

Commit 99251c3

Browse filesBrowse files
committed
Reworking feature so that json_manifest_path is the config key, and is all that's needed to activate
This keeps the original behavior of version_strategy: this is always a service id
1 parent aa32896 commit 99251c3
Copy full SHA for 99251c3

File tree

8 files changed

+96
-83
lines changed
Filter options

8 files changed

+96
-83
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7-
* A new version_strategy called json_manifest was added that reads a JSON manifest
8-
to load the correct, versioned paths of assets.
7+
* A new version strategy option called json_manifest_path was added
8+
that allows you to use the JsonManifestVersionStrategy.
99
* Added support for the `controller.service_arguments` tag, for injecting services into controllers' actions
1010
* Deprecated `cache:clear` with warmup (always call it with `--no-warmup`)
1111
* Deprecated the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
551551
->scalarNode('version_strategy')->defaultNull()->end()
552552
->scalarNode('version')->defaultNull()->end()
553553
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
554-
->scalarNode('manifest_path')->defaultNull()->end()
554+
->scalarNode('json_manifest_path')->defaultNull()->end()
555555
->scalarNode('base_path')->defaultValue('')->end()
556556
->arrayNode('base_urls')
557557
->requiresAtLeastOneElement()
@@ -570,9 +570,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
570570
->end()
571571
->validate()
572572
->ifTrue(function ($v) {
573-
return isset($v['version_strategy']) && $v['version_strategy'] === 'json_manifest' && !isset($v['manifest_path']);
573+
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
574574
})
575-
->thenInvalid('You must configure the "manifest_path" key in order to use the "json_manifest" "version_strategy".')
575+
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".')
576+
->end()
577+
->validate()
578+
->ifTrue(function ($v) {
579+
return isset($v['version']) && isset($v['json_manifest_path']);
580+
})
581+
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets".')
576582
->end()
577583
->fixXmlConfig('package')
578584
->children()
@@ -589,7 +595,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
589595
->end()
590596
->end()
591597
->scalarNode('version_format')->defaultNull()->end()
592-
->scalarNode('manifest_path')->defaultNull()->end()
598+
->scalarNode('json_manifest_path')->defaultNull()->end()
593599
->scalarNode('base_path')->defaultValue('')->end()
594600
->arrayNode('base_urls')
595601
->requiresAtLeastOneElement()
@@ -608,9 +614,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
608614
->end()
609615
->validate()
610616
->ifTrue(function ($v) {
611-
return isset($v['version_strategy']) && $v['version_strategy'] === 'json_manifest' && !isset($v['manifest_path']);
617+
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
618+
})
619+
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.')
620+
->end()
621+
->validate()
622+
->ifTrue(function ($v) {
623+
return isset($v['version']) && isset($v['json_manifest_path']);
612624
})
613-
->thenInvalid('You must configure the "manifest_path" key in order to use the "json_manifest" "version_strategy".')
625+
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.')
614626
->end()
615627
->end()
616628
->end()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+27-32Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,9 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
808808
$defaultVersion = null;
809809

810810
if ($config['version_strategy']) {
811-
if ($config['version_strategy'] == 'json_manifest') {
812-
$defaultVersion = $this->createJsonManifestVersion($container, $config['manifest_path'], '_default');
813-
} else {
814-
$defaultVersion = new Reference($config['version_strategy']);
815-
}
811+
$defaultVersion = new Reference($config['version_strategy']);
816812
} else {
817-
$defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], '_default');
813+
$defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], $config['json_manifest_path'], '_default');
818814
}
819815

820816
$defaultPackage = $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
@@ -823,16 +819,15 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
823819
$namedPackages = array();
824820
foreach ($config['packages'] as $name => $package) {
825821
if (null !== $package['version_strategy']) {
826-
if ($package['version_strategy'] == 'json_manifest') {
827-
$version = $this->createJsonManifestVersion($container, $package['manifest_path'], $name);
828-
} else {
829-
$version = new Reference($package['version_strategy']);
830-
}
831-
} elseif (!array_key_exists('version', $package)) {
822+
$version = new Reference($package['version_strategy']);
823+
} elseif (!array_key_exists('version', $package) && null === $package['json_manifest_path']) {
824+
// if neither version nor json_manifest_path are specified, use the default
832825
$version = $defaultVersion;
833826
} else {
827+
// let format fallback to main version_format
834828
$format = $package['version_format'] ?: $config['version_format'];
835-
$version = $this->createVersion($container, $package['version'], $format, $name);
829+
$version = isset($package['version']) ? $package['version'] : null;
830+
$version = $this->createVersion($container, $version, $format, $package['json_manifest_path'], $name);
836831
}
837832

838833
$container->setDefinition('assets._package_'.$name, $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version));
@@ -864,30 +859,30 @@ private function createPackageDefinition($basePath, array $baseUrls, Reference $
864859
return $package;
865860
}
866861

867-
private function createVersion(ContainerBuilder $container, $version, $format, $name)
862+
private function createVersion(ContainerBuilder $container, $version, $format, $jsonManifestPath, $name)
868863
{
869-
if (null === $version) {
870-
return new Reference('assets.empty_version_strategy');
871-
}
864+
// Configuration prevents $version and $jsonManifestPath from being set
865+
if (null !== $version) {
866+
$def = new ChildDefinition('assets.static_version_strategy');
867+
$def
868+
->replaceArgument(0, $version)
869+
->replaceArgument(1, $format)
870+
;
871+
$container->setDefinition('assets._version_'.$name, $def);
872872

873-
$def = new ChildDefinition('assets.static_version_strategy');
874-
$def
875-
->replaceArgument(0, $version)
876-
->replaceArgument(1, $format)
877-
;
878-
$container->setDefinition('assets._version_'.$name, $def);
873+
return new Reference('assets._version_'.$name);
874+
}
879875

880-
return new Reference('assets._version_'.$name);
881-
}
876+
if (null !== $jsonManifestPath) {
877+
$def = new ChildDefinition('assets.json_manifest_version_strategy');
878+
$def->replaceArgument(0, $jsonManifestPath);
879+
$def->setPublic(false);
880+
$container->setDefinition('assets._version_'.$name, $def);
882881

883-
private function createJsonManifestVersion(ContainerBuilder $container, $manifestPath, $name)
884-
{
885-
$def = new ChildDefinition('assets.json_manifest_version_strategy');
886-
$def->replaceArgument(0, $manifestPath);
887-
$def->setPublic(false);
888-
$container->setDefinition('assets._version_'.$name, $def);
882+
return new Reference('assets._version_'.$name);
883+
}
889884

890-
return new Reference('assets._version_'.$name);
885+
return new Reference('assets.empty_version_strategy');
891886
}
892887

893888
/**

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<xsd:attribute name="version-strategy" type="xsd:string" />
132132
<xsd:attribute name="version" type="xsd:string" />
133133
<xsd:attribute name="version-format" type="xsd:string" />
134-
<xsd:attribute name="manifest-path" type="xsd:string" />
134+
<xsd:attribute name="json-manifest-path" type="xsd:string" />
135135
</xsd:complexType>
136136

137137
<xsd:complexType name="package">
@@ -144,7 +144,7 @@
144144
<xsd:attribute name="version-strategy" type="xsd:string" />
145145
<xsd:attribute name="version" type="xsd:string" />
146146
<xsd:attribute name="version-format" type="xsd:string" />
147-
<xsd:attribute name="manifest-path" type="xsd:string" />
147+
<xsd:attribute name="json-manifest-path" type="xsd:string" />
148148
</xsd:complexType>
149149

150150
<xsd:complexType name="templating">

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+44-36Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
1616
use Symfony\Bundle\FullStack;
17+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1718
use Symfony\Component\Config\Definition\Processor;
1819

1920
class ConfigurationTest extends TestCase
@@ -120,55 +121,62 @@ public function testAssetsCanBeEnabled()
120121
'base_path' => '',
121122
'base_urls' => array(),
122123
'packages' => array(),
123-
'manifest_path' => null,
124+
'json_manifest_path' => null,
124125
);
125126

126127
$this->assertEquals($defaultConfig, $config['assets']);
127128
}
128129

129130
/**
130-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
131-
* @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets".
131+
* @dataProvider provideInvalidAssetConfigurationTests
132132
*/
133-
public function testInvalidVersionStrategy()
133+
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
134134
{
135+
$this->expectException(InvalidConfigurationException::class);
136+
$this->expectExceptionMessage($expectedMessage);
137+
135138
$processor = new Processor();
136-
$configuration = new Configuration(true);
137-
$processor->processConfiguration($configuration, array(
138-
array(
139-
'assets' => array(
140-
'base_urls' => '//example.com',
141-
'version' => 1,
142-
'version_strategy' => 'foo',
139+
$configuration = new Configuration(true);
140+
$processor->processConfiguration($configuration, array(
141+
array(
142+
'assets' => $assetConfig
143143
),
144-
),
145-
));
144+
));
146145
}
147146

148-
/**
149-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
150-
* @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets" packages.
151-
*/
152-
public function testInvalidPackageVersionStrategy()
147+
public function provideInvalidAssetConfigurationTests()
153148
{
154-
$processor = new Processor();
155-
$configuration = new Configuration(true);
156-
157-
$processor->processConfiguration($configuration, array(
158-
array(
159-
'assets' => array(
160-
'base_urls' => '//example.com',
161-
'version' => 1,
162-
'packages' => array(
163-
'foo' => array(
164-
'base_urls' => '//example.com',
165-
'version' => 1,
166-
'version_strategy' => 'foo',
167-
),
168-
),
149+
// helper to turn config into embedded package config
150+
$createPackageConfig = function(array $packageConfig) {
151+
return array(
152+
'base_urls' => '//example.com',
153+
'version' => 1,
154+
'packages' => array(
155+
'foo' => $packageConfig,
169156
),
170-
),
171-
));
157+
);
158+
};
159+
160+
$config = array(
161+
'version' => 1,
162+
'version_strategy' => 'foo',
163+
);
164+
yield array($config, 'You cannot use both "version_strategy" and "version" at the same time under "assets".');
165+
yield array($createPackageConfig($config), 'You cannot use both "version_strategy" and "version" at the same time under "assets" packages.');
166+
167+
$config = array(
168+
'json_manifest_path' => '/foo.json',
169+
'version_strategy' => 'foo',
170+
);
171+
yield array($config, 'You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".');
172+
yield array($createPackageConfig($config), 'You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.');
173+
174+
$config = array(
175+
'json_manifest_path' => '/foo.json',
176+
'version' => '1',
177+
);
178+
yield array($config, 'You cannot use both "version" and "json_manifest_path" at the same time under "assets".');
179+
yield array($createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.');
172180
}
173181

174182
protected static function getBundleDefaultConfig()
@@ -275,7 +283,7 @@ protected static function getBundleDefaultConfig()
275283
'base_path' => '',
276284
'base_urls' => array(),
277285
'packages' => array(),
278-
'manifest_path' => null,
286+
'json_manifest_path' => null,
279287
),
280288
'cache' => array(
281289
'pools' => array(),

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
'version_strategy' => 'assets.custom_version_strategy',
2626
),
2727
'json_manifest_strategy' => array(
28-
'version_strategy' => 'json_manifest',
29-
'manifest_path' => '/path/to/manifest.json',
28+
'json_manifest_path' => '/path/to/manifest.json',
3029
),
3130
),
3231
),

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<framework:package name="bar_version_strategy" version-strategy="assets.custom_version_strategy">
2222
<framework:base-url>https://bar_version_strategy.example.com</framework:base-url>
2323
</framework:package>
24-
<framework:package name="json_manifest_strategy" version-strategy="json_manifest" manifest-path="/path/to/manifest.json" />
24+
<framework:package name="json_manifest_strategy" json-manifest-path="/path/to/manifest.json" />
2525
</framework:assets>
2626
</framework:config>
2727
</container>

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ framework:
1818
base_urls: ["https://bar_version_strategy.example.com"]
1919
version_strategy: assets.custom_version_strategy
2020
json_manifest_strategy:
21-
version_strategy: json_manifest
22-
manifest_path: '/path/to/manifest.json'
21+
json_manifest_path: '/path/to/manifest.json'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.