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 7a652ae

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 ee1294b commit 7a652ae
Copy full SHA for 7a652ae

File tree

Expand file treeCollapse file tree

8 files changed

+96
-83
lines changed
Filter options
Expand file treeCollapse file tree

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
* Changed default configuration for
1010
assets/forms/validation/translation/serialization/csrf from `canBeEnabled()` to
1111
`canBeDisabled()` when Flex is used

‎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
@@ -542,7 +542,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
542542
->scalarNode('version_strategy')->defaultNull()->end()
543543
->scalarNode('version')->defaultNull()->end()
544544
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
545-
->scalarNode('manifest_path')->defaultNull()->end()
545+
->scalarNode('json_manifest_path')->defaultNull()->end()
546546
->scalarNode('base_path')->defaultValue('')->end()
547547
->arrayNode('base_urls')
548548
->requiresAtLeastOneElement()
@@ -561,9 +561,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
561561
->end()
562562
->validate()
563563
->ifTrue(function ($v) {
564-
return isset($v['version_strategy']) && $v['version_strategy'] === 'json_manifest' && !isset($v['manifest_path']);
564+
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
565565
})
566-
->thenInvalid('You must configure the "manifest_path" key in order to use the "json_manifest" "version_strategy".')
566+
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets".')
567+
->end()
568+
->validate()
569+
->ifTrue(function ($v) {
570+
return isset($v['version']) && isset($v['json_manifest_path']);
571+
})
572+
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets".')
567573
->end()
568574
->fixXmlConfig('package')
569575
->children()
@@ -580,7 +586,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
580586
->end()
581587
->end()
582588
->scalarNode('version_format')->defaultNull()->end()
583-
->scalarNode('manifest_path')->defaultNull()->end()
589+
->scalarNode('json_manifest_path')->defaultNull()->end()
584590
->scalarNode('base_path')->defaultValue('')->end()
585591
->arrayNode('base_urls')
586592
->requiresAtLeastOneElement()
@@ -599,9 +605,15 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
599605
->end()
600606
->validate()
601607
->ifTrue(function ($v) {
602-
return isset($v['version_strategy']) && $v['version_strategy'] === 'json_manifest' && !isset($v['manifest_path']);
608+
return isset($v['version_strategy']) && isset($v['json_manifest_path']);
609+
})
610+
->thenInvalid('You cannot use both "version_strategy" and "json_manifest_path" at the same time under "assets" packages.')
611+
->end()
612+
->validate()
613+
->ifTrue(function ($v) {
614+
return isset($v['version']) && isset($v['json_manifest_path']);
603615
})
604-
->thenInvalid('You must configure the "manifest_path" key in order to use the "json_manifest" "version_strategy".')
616+
->thenInvalid('You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.')
605617
->end()
606618
->end()
607619
->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
@@ -793,13 +793,9 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
793793
$defaultVersion = null;
794794

795795
if ($config['version_strategy']) {
796-
if ($config['version_strategy'] == 'json_manifest') {
797-
$defaultVersion = $this->createJsonManifestVersion($container, $config['manifest_path'], '_default');
798-
} else {
799-
$defaultVersion = new Reference($config['version_strategy']);
800-
}
796+
$defaultVersion = new Reference($config['version_strategy']);
801797
} else {
802-
$defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], '_default');
798+
$defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], $config['json_manifest_path'], '_default');
803799
}
804800

805801
$defaultPackage = $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
@@ -808,16 +804,15 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
808804
$namedPackages = array();
809805
foreach ($config['packages'] as $name => $package) {
810806
if (null !== $package['version_strategy']) {
811-
if ($package['version_strategy'] == 'json_manifest') {
812-
$version = $this->createJsonManifestVersion($container, $package['manifest_path'], $name);
813-
} else {
814-
$version = new Reference($package['version_strategy']);
815-
}
816-
} elseif (!array_key_exists('version', $package)) {
807+
$version = new Reference($package['version_strategy']);
808+
} elseif (!array_key_exists('version', $package) && null === $package['json_manifest_path']) {
809+
// if neither version nor json_manifest_path are specified, use the default
817810
$version = $defaultVersion;
818811
} else {
812+
// let format fallback to main version_format
819813
$format = $package['version_format'] ?: $config['version_format'];
820-
$version = $this->createVersion($container, $package['version'], $format, $name);
814+
$version = isset($package['version']) ? $package['version'] : null;
815+
$version = $this->createVersion($container, $version, $format, $package['json_manifest_path'], $name);
821816
}
822817

823818
$container->setDefinition('assets._package_'.$name, $this->createPackageDefinition($package['base_path'], $package['base_urls'], $version));
@@ -849,30 +844,30 @@ private function createPackageDefinition($basePath, array $baseUrls, Reference $
849844
return $package;
850845
}
851846

852-
private function createVersion(ContainerBuilder $container, $version, $format, $name)
847+
private function createVersion(ContainerBuilder $container, $version, $format, $jsonManifestPath, $name)
853848
{
854-
if (null === $version) {
855-
return new Reference('assets.empty_version_strategy');
856-
}
849+
// Configuration prevents $version and $jsonManifestPath from being set
850+
if (null !== $version) {
851+
$def = new ChildDefinition('assets.static_version_strategy');
852+
$def
853+
->replaceArgument(0, $version)
854+
->replaceArgument(1, $format)
855+
;
856+
$container->setDefinition('assets._version_'.$name, $def);
857857

858-
$def = new ChildDefinition('assets.static_version_strategy');
859-
$def
860-
->replaceArgument(0, $version)
861-
->replaceArgument(1, $format)
862-
;
863-
$container->setDefinition('assets._version_'.$name, $def);
858+
return new Reference('assets._version_'.$name);
859+
}
864860

865-
return new Reference('assets._version_'.$name);
866-
}
861+
if (null !== $jsonManifestPath) {
862+
$def = new ChildDefinition('assets.json_manifest_version_strategy');
863+
$def->replaceArgument(0, $jsonManifestPath);
864+
$def->setPublic(false);
865+
$container->setDefinition('assets._version_'.$name, $def);
867866

868-
private function createJsonManifestVersion(ContainerBuilder $container, $manifestPath, $name)
869-
{
870-
$def = new ChildDefinition('assets.json_manifest_version_strategy');
871-
$def->replaceArgument(0, $manifestPath);
872-
$def->setPublic(false);
873-
$container->setDefinition('assets._version_'.$name, $def);
867+
return new Reference('assets._version_'.$name);
868+
}
874869

875-
return new Reference('assets._version_'.$name);
870+
return new Reference('assets.empty_version_strategy');
876871
}
877872

878873
/**

‎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
@@ -117,55 +118,62 @@ public function testAssetsCanBeEnabled()
117118
'base_path' => '',
118119
'base_urls' => array(),
119120
'packages' => array(),
120-
'manifest_path' => null,
121+
'json_manifest_path' => null,
121122
);
122123

123124
$this->assertEquals($defaultConfig, $config['assets']);
124125
}
125126

126127
/**
127-
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
128-
* @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets".
128+
* @dataProvider provideInvalidAssetConfigurationTests
129129
*/
130-
public function testInvalidVersionStrategy()
130+
public function testInvalidAssetsConfiguration(array $assetConfig, $expectedMessage)
131131
{
132+
$this->expectException(InvalidConfigurationException::class);
133+
$this->expectExceptionMessage($expectedMessage);
134+
132135
$processor = new Processor();
133-
$configuration = new Configuration(true);
134-
$processor->processConfiguration($configuration, array(
135-
array(
136-
'assets' => array(
137-
'base_urls' => '//example.com',
138-
'version' => 1,
139-
'version_strategy' => 'foo',
136+
$configuration = new Configuration(true);
137+
$processor->processConfiguration($configuration, array(
138+
array(
139+
'assets' => $assetConfig
140140
),
141-
),
142-
));
141+
));
143142
}
144143

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

171179
protected static function getBundleDefaultConfig()
@@ -271,7 +279,7 @@ protected static function getBundleDefaultConfig()
271279
'base_path' => '',
272280
'base_urls' => array(),
273281
'packages' => array(),
274-
'manifest_path' => null,
282+
'json_manifest_path' => null,
275283
),
276284
'cache' => array(
277285
'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.