8000 [2.7][Asset] Ability to set empty version strategy in packages by ewgRa · Pull Request #16511 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function getConfigTreeBuilder()

foreach ($v['templating']['packages'] as $name => $config) {
$v['assets']['packages'][$name] = array(
'version' => (string) $config['version'],
'version' => null === $config['version'] ? null : (string) $config['version'],
'version_format' => $config['version_format'],
'base_path' => '',
'base_urls' => array_values(array_unique(array_merge($config['base_urls']['http'], $config['base_urls']['ssl']))),
Expand Down Expand Up @@ -488,7 +488,13 @@ private function addTemplatingSection(ArrayNodeDefinition $rootNode)
->prototype('array')
->fixXmlConfig('base_url')
->children()
->scalarNode('version')->defaultNull()->end()
->scalarNode('version')
->defaultNull()
->beforeNormalization()
->ifTrue(function ($v) { return '' === $v; })
->then(function ($v) { return; })
->end()
->end()
->scalarNode('version_format')->defaultValue('%%s?%%s')->end()
->arrayNode('base_urls')
->performNoDeepMerging()
Expand 10BC0 Down Expand Up @@ -547,7 +553,12 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode)
->prototype('array')
->fixXmlConfig('base_url')
->children()
->scalarNode('version')->defaultNull()->end()
->scalarNode('version')
->beforeNormalization()
->ifTrue(function ($v) { return '' === $v; })
->then(function ($v) { return; })
->end()
->end()
->scalarNode('version_format')->defaultNull()->end()
->scalarNode('base_path')->defaultValue('')->end()
->arrayNode('base_urls')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ private function registerAssetsConfiguration(array $config, ContainerBuilder $co

$namedPackages = array();
foreach ($config['packages'] as $name => $package) {
if (null === $package['version']) {
if (!array_key_exists('version', $package)) {
$version = $defaultVersion;
} else {
$format = $package['version_format'] ?: $config['version_format'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
'bar' => array(
'base_urls' => array('https://bar2.example.com'),
),
'bar_null_version' => array(
'version' => null,
'base_urls' => array('https://bar3.example.com'),
),
),
),
));
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
'bar' => array(
'base_urls' => array('https://bar2.example.com'),
),
'bar_null_version' => array(
'version' => null,
'base_urls' => array('https://bar3.example.com'),
),
),
),
));
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<framework:package name="bar">
<framework:base-url>https://bar2.example.com</framework:base-url>
</framework:package>
<framework:package name="bar_null_version" version="">
<framework:base-url>https://bar3.example.com</framework:base-url>
</framework:package>
</framework:assets>
</framework:config>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<framework:package name="bar">
<framework:base-url>https://bar2.example.com</framework:base-url>
</framework:package>
<framework:package name="bar_null_version" version="">
<framework:base-url>https://bar3.example.com</framework:base-url>
</framework:package>
</framework:templating>
</framework:config>
</container>
Original file line number Diff line number Diff line change
5074 Expand Up @@ -14,3 +14,6 @@ framework:
version_format: %%s-%%s
bar:
base_urls: ["https://bar2.example.com"]
bar_null_version:
version: null
base_urls: "https://bar3.example.com"
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ framework:
version_format: %%s-%%s
bar:
base_urls: "https://bar2.example.com"
bar_null_version:
version: null
base_urls: "https://bar3.example.com"
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private function checkAssetsPackages(ContainerBuilder $container, $legacy = fals

// packages
$packages = $packages->getArgument(1);
$this->assertCount($legacy ? 3 : 4, $packages);
$this->assertCount($legacy ? 4 : 5, $packages);

if (!$legacy) {
$package = $container->getDefinition($packages['images_path']);
Expand All @@ -525,7 +525,10 @@ private function checkAssetsPackages(ContainerBuilder $container, $legacy = fals
$this->assertPathPackage($container, $package, '', '1.0.0', '%%s-%%s');

$package = $container->getDefinition($packages['bar']);
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), $legacy ? '' : 'SomeVersionScheme', $legacy ? '%%s?%%s' : '%%s?version=%%s');
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), $legacy ? null : 'SomeVersionScheme', $legacy ? '%%s?%%s' : '%%s?version=%%s');

$this->assertEquals($legacy ? 'assets.empty_version_strategy' : 'assets._version__default', (string) $container->getDefinition('assets._package_bar')->getArgument(1));
$this->assertEquals('assets.empty_version_strategy', (string) $container->getDefinition('assets._package_bar_null_version')->getArgument(1));
}

private function assertPathPackage(ContainerBuilder $container, DefinitionDecorator $package, $basePath, $version, $format)
Expand Down
0