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 4b2019d

Browse filesBrowse files
bug #31198 [FrameworkBundle] Fix framework bundle lock configuration not working as expected (HypeMC)
This PR was squashed before being merged into the 3.4 branch (closes #31198). Discussion ---------- [FrameworkBundle] Fix framework bundle lock configuration not working as expected | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31197 | License | MIT | Doc PR | symfony/symfony-docs#11465 & symfony/symfony-docs#11466 This fixes #31197 and makes the lock configuration work with installations that are not full stack ones and configurations that use xml files. Commits ------- c7af2df [FrameworkBundle] Fix framework bundle lock configuration not working as expected
2 parents ad66a16 + c7af2df commit 4b2019d
Copy full SHA for 4b2019d

File tree

2 files changed

+81
-2
lines changed
Filter options

2 files changed

+81
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+18-2Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,11 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
929929
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
930930
->end()
931931
->beforeNormalization()
932-
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']); })
932+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
933+
->then(function ($v) { return $v + ['enabled' => true]; })
934+
->end()
935+
->beforeNormalization()
936+
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
933937
->then(function ($v) {
934938
$e = $v['enabled'];
935939
unset($v['enabled']);
@@ -948,7 +952,19 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
948952
->end()
949953
->beforeNormalization()
950954
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
951-
->then(function ($v) { return ['default' => $v]; })
955+
->then(function ($v) {
956+
$resources = [];
957+
foreach ($v as $resource) {
958+
$resources = array_merge_recursive(
959+
$resources,
960+
\is_array($resource) && isset($resource['name'])
961+
? [$resource['name'] => $resource['value']]
962+
: ['default' => $resource]
963+
);
964+
}
965+
966+
return $resources;
967+
})
952968
->end()
953969
->prototype('array')
954970
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+63Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,69 @@ public function provideInvalidAssetConfigurationTests()
292292
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
293293
}
294294

295+
/**
296+
* @dataProvider provideValidLockConfigurationTests
297+
*/
298+
public function testValidLockConfiguration($lockConfig, $processedConfig)
299+
{
300+
$processor = new Processor();
301+
$configuration = new Configuration(true);
302+
$config = $processor->processConfiguration($configuration, [
303+
[
304+
'lock' => $lockConfig,
305+
],
306+
]);
307+
308+
$this->assertArrayHasKey('lock', $config);
309+
310+
$this->assertEquals($processedConfig, $config['lock']);
311+
}
312+
313+
public function provideValidLockConfigurationTests()
314+
{
315+
yield [null, ['enabled' => true, 'resources' => ['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]]];
316+
317+
yield ['flock', ['enabled' => true, 'resources' => ['default' => ['flock']]]];
318+
yield [['flock', 'semaphore'], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
319+
yield [['foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
320+
yield [['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
321+
yield [['default' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
322+
323+
yield [['enabled' => false, 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
324+
yield [['enabled' => false, ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
325+
yield [['enabled' => false, 'foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
326+
yield [['enabled' => false, 'foo' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
327+
yield [['enabled' => false, 'default' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
328+
329+
yield [['resources' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
330+
yield [['resources' => ['flock', 'semaphore']], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
331+
yield [['resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
332+
yield [['resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
333+
yield [['resources' => ['default' => 'flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
334+
335+
yield [['enabled' => false, 'resources' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
336+
yield [['enabled' => false, 'resources' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
337+
yield [['enabled' => false, 'resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
338+
yield [['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
339+
yield [['enabled' => false, 'resources' => ['default' => 'flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
340+
341+
// xml
342+
343+
yield [['resource' => ['flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
344+
yield [['resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
345+
yield [['resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => true, 'resources' => ['foo' => ['flock']]]];
346+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore']]]];
347+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
348+
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
349+
350+
yield [['enabled' => false, 'resource' => ['flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
351+
yield [['enabled' => false, 'resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
352+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => false, 'resources' => ['foo' => ['flock']]]];
353+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
354+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
355+
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
356+
}
357+
295358
protected static function getBundleDefaultConfig()
296359
{
297360
return [

0 commit comments

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