diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
index a638daeb8a731..2276b26db58c0 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
@@ -364,6 +364,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
->canBeUnset()
->fixXmlConfig('base_url')
->children()
+ ->scalarNode('version_strategy')->defaultNull()->end()
->scalarNode('version')->defaultNull()->end()
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
->scalarNode('base_path')->defaultValue('')->end()
@@ -376,6 +377,12 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->end()
->end()
+ ->validate()
+ ->ifTrue(function ($v) {
+ return (null !== $v['version_strategy'] && null !== $v['version']);
+ })
+ ->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets".')
+ ->end()
->fixXmlConfig('package')
->children()
->arrayNode('packages')
@@ -383,6 +390,7 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
->prototype('array')
->fixXmlConfig('base_url')
->children()
+ ->scalarNode('version_strategy')->defaultNull()->end()
->scalarNode('version')->defaultNull()->end()
->scalarNode('version_format')->defaultNull()->end()
->scalarNode('base_path')->defaultValue('')->end()
@@ -395,6 +403,12 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
->prototype('scalar')->end()
->end()
->end()
+ ->validate()
+ ->ifTrue(function ($v) {
+ return (null !== $v['version_strategy'] && null !== $v['version']);
+ })
+ ->thenInvalid('You cannot use both "version_strategy" and "version" at the same time under "assets" packages.')
+ ->end()
->end()
->end()
->end()
diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index 7d8afee62b043..326c0083a498d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -561,14 +561,22 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co
{
$loader->load('assets.xml');
- $defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], '_default');
+ $defaultVersion = null;
+
+ if ($config['version_strategy']) {
+ $defaultVersion = new Reference($config['version_strategy']);
+ } else {
+ $defaultVersion = $this->createVersion($container, $config['version'], $config['version_format'], '_default');
+ }
$defaultPackage = $this->createPackageDefinition($config['base_path'], $config['base_urls'], $defaultVersion);
$container->setDefinition('assets._default_package', $defaultPackage);
$namedPackages = array();
foreach ($config['packages'] as $name => $package) {
- if (null === $package['version']) {
+ if (null !== $package['version_strategy']) {
+ $version = new Reference($package['version_strategy']);
+ } elseif (null === $package['version']) {
$version = $defaultVersion;
} else {
$format = $package['version_format'] ?: $config['version_format'];
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
index 5e26bd11d3520..cead2295ed1ac 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
@@ -126,6 +126,7 @@
+
@@ -137,6 +138,7 @@
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
index d0dba2badf4f7..a4d086117567d 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
@@ -91,6 +91,7 @@ public function testInvalidValueTrustedProxies()
{
$processor = new Processor();
$configuration = new Configuration(true);
+
$processor->processConfiguration($configuration, array(
array(
'secret' => 's3cr3t',
@@ -106,6 +107,7 @@ public function testAssetsCanBeEnabled()
$config = $processor->processConfiguration($configuration, array(array('assets' => null)));
$defaultConfig = array(
+ 'version_strategy' => null,
'version' => null,
'version_format' => '%%s?%%s',
'base_path' => '',
@@ -116,6 +118,51 @@ public function testAssetsCanBeEnabled()
$this->assertEquals($defaultConfig, $config['assets']);
}
+ /**
+ * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
+ * @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets".
+ */
+ public function testInvalidVersionStrategy()
+ {
+ $processor = new Processor();
+ $configuration = new Configuration(true);
+ $processor->processConfiguration($configuration, array(
+ array(
+ 'assets' => array(
+ 'base_urls' => '//example.com',
+ 'version' => 1,
+ 'version_strategy' => 'foo',
+ ),
+ ),
+ ));
+ }
+
+ /**
+ * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
+ * @expectedExceptionMessage You cannot use both "version_strategy" and "version" at the same time under "assets" packages.
+ */
+ public function testInvalidPackageVersionStrategy()
+ {
+ $processor = new Processor();
+ $configuration = new Configuration(true);
+
+ $processor->processConfiguration($configuration, array(
+ array(
+ 'assets' => array(
+ 'base_urls' => '//example.com',
+ 'version' => 1,
+ 'packages' => array(
+ 'foo' => array(
+ 'base_urls' => '//example.com',
+ 'version' => 1,
+ 'version_strategy' => 'foo',
+ ),
+ ),
+ ),
+ ),
+ ));
+ }
+
protected static function getBundleDefaultConfig()
{
return array(
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php
index e3532a7747cc6..3cfc5c1bc0cc4 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets.php
@@ -20,6 +20,10 @@
'bar' => array(
'base_urls' => array('https://bar2.example.com'),
),
+ 'bar_version_strategy' => array(
+ 'base_urls' => array('https://bar2.example.com'),
+ 'version_strategy' => 'assets.custom_version_strategy',
+ ),
),
),
));
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets_version_strategy_as_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets_version_strategy_as_service.php
new file mode 100644
index 0000000000000..4f9123aefb0f5
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/assets_version_strategy_as_service.php
@@ -0,0 +1,8 @@
+loadFromExtension('framework', array(
+ 'assets' => array(
+ 'version_strategy' => 'assets.custom_version_strategy',
+ 'base_urls' => 'http://cdn.example.com',
+ ),
+));
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml
index e39e15f900528..b99952b2923d3 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets.xml
@@ -18,6 +18,9 @@
https://bar2.example.com
+
+ https://bar_version_strategy.example.com
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets_version_strategy_as_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets_version_strategy_as_service.xml
new file mode 100644
index 0000000000000..353ac487e4044
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/assets_version_strategy_as_service.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ http://cdn.example.com
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml
index 193dc59dfba3a..ec74f1beb8015 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets.yml
@@ -14,3 +14,6 @@ framework:
version_format: %%s-%%s
bar:
base_urls: ["https://bar2.example.com"]
+ bar_version_strategy:
+ base_urls: ["https://bar_version_strategy.example.com"]
+ version_strategy: assets.custom_version_strategy
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets_version_strategy_as_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets_version_strategy_as_service.yml
new file mode 100644
index 0000000000000..2528462f83cb5
--- /dev/null
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/assets_version_strategy_as_service.yml
@@ -0,0 +1,4 @@
+framework:
+ assets:
+ version_strategy: assets.custom_version_strategy
+ base_urls: http://cdn.example.com
diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
index f6be36dae8e50..34889a13a17ce 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php
@@ -209,7 +209,7 @@ public function testAssets()
// packages
$packages = $packages->getArgument(1);
- $this->assertCount(4, $packages);
+ $this->assertCount(5, $packages);
$package = $container->getDefinition($packages['images_path']);
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
@@ -222,6 +222,19 @@ public function testAssets()
$package = $container->getDefinition($packages['bar']);
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
+
+ $package = $container->getDefinition($packages['bar_version_strategy']);
+ $this->assertEquals('assets.custom_version_strategy', (string) $package->getArgument(1));
+ }
+
+ public function testAssetsDefaultVersionStrategyAsService()
+ {
+ $container = $this->createContainerFromFile('assets_version_strategy_as_service');
+ $packages = $container->getDefinition('assets.packages');
+
+ // default package
+ $defaultPackage = $container->getDefinition($packages->getArgument(0));
+ $this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1));
}
public function testTranslator()
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