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 | https://github.com/symfony/symfony-docs/pull/11465 & https://github.com/symfony/symfony-docs/pull/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
-------
c7af2df340
[FrameworkBundle] Fix framework bundle lock configuration not working as expected
This commit is contained in:
commit
4b2019db78
@ -929,7 +929,11 @@ class Configuration implements ConfigurationInterface
|
|||||||
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
|
->ifString()->then(function ($v) { return ['enabled' => true, 'resources' => $v]; })
|
||||||
->end()
|
->end()
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']); })
|
->ifTrue(function ($v) { return \is_array($v) && !isset($v['enabled']); })
|
||||||
|
->then(function ($v) { return $v + ['enabled' => true]; })
|
||||||
|
->end()
|
||||||
|
->beforeNormalization()
|
||||||
|
->ifTrue(function ($v) { return \is_array($v) && !isset($v['resources']) && !isset($v['resource']); })
|
||||||
->then(function ($v) {
|
->then(function ($v) {
|
||||||
$e = $v['enabled'];
|
$e = $v['enabled'];
|
||||||
unset($v['enabled']);
|
unset($v['enabled']);
|
||||||
@ -948,7 +952,19 @@ class Configuration implements ConfigurationInterface
|
|||||||
->end()
|
->end()
|
||||||
->beforeNormalization()
|
->beforeNormalization()
|
||||||
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
|
->ifTrue(function ($v) { return \is_array($v) && array_keys($v) === range(0, \count($v) - 1); })
|
||||||
->then(function ($v) { return ['default' => $v]; })
|
->then(function ($v) {
|
||||||
|
$resources = [];
|
||||||
|
foreach ($v as $resource) {
|
||||||
|
$resources = array_merge_recursive(
|
||||||
|
$resources,
|
||||||
|
\is_array($resource) && isset($resource['name'])
|
||||||
|
? [$resource['name'] => $resource['value']]
|
||||||
|
: ['default' => $resource]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $resources;
|
||||||
|
})
|
||||||
->end()
|
->end()
|
||||||
->prototype('array')
|
->prototype('array')
|
||||||
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
|
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
|
||||||
|
@ -292,6 +292,69 @@ class ConfigurationTest extends TestCase
|
|||||||
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
|
yield [$createPackageConfig($config), 'You cannot use both "version" and "json_manifest_path" at the same time under "assets" packages.'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider provideValidLockConfigurationTests
|
||||||
|
*/
|
||||||
|
public function testValidLockConfiguration($lockConfig, $processedConfig)
|
||||||
|
{
|
||||||
|
$processor = new Processor();
|
||||||
|
$configuration = new Configuration(true);
|
||||||
|
$config = $processor->processConfiguration($configuration, [
|
||||||
|
[
|
||||||
|
'lock' => $lockConfig,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('lock', $config);
|
||||||
|
|
||||||
|
$this->assertEquals($processedConfig, $config['lock']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideValidLockConfigurationTests()
|
||||||
|
{
|
||||||
|
yield [null, ['enabled' => true, 'resources' => ['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']]]];
|
||||||
|
|
||||||
|
yield ['flock', ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['flock', 'semaphore'], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore'], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['default' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||||
|
|
||||||
|
yield [['enabled' => false, 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['enabled' => false, ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'foo' => 'flock', 'bar' => 'semaphore'], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'foo' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'default' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||||
|
|
||||||
|
yield [['resources' => 'flock'], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['resources' => ['flock', 'semaphore']], ['enabled' => true, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['resources' => ['default' => 'flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||||
|
|
||||||
|
yield [['enabled' => false, 'resources' => 'flock'], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['enabled' => false, 'resources' => ['flock', 'semaphore']], ['enabled' => false, 'resources' => ['default' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resources' => ['foo' => 'flock', 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => 'semaphore']], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resources' => ['default' => 'flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||||
|
|
||||||
|
// xml
|
||||||
|
|
||||||
|
yield [['resource' => ['flock']], ['enabled' => true, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
|
||||||
|
yield [['resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => true, 'resources' => ['foo' => ['flock']]]];
|
||||||
|
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => true, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||||
|
|
||||||
|
yield [['enabled' => false, 'resource' => ['flock']], ['enabled' => false, 'resources' => ['default' => ['flock']]]];
|
||||||
|
yield [['enabled' => false, 'resource' => ['flock', ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['default' => ['flock'], 'foo' => ['semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock']]], ['enabled' => false, 'resources' => ['foo' => ['flock']]]];
|
||||||
|
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock'], 'bar' => ['semaphore']]]];
|
||||||
|
yield [['enabled' => false, 'resource' => [['name' => 'foo', 'value' => 'flock'], ['name' => 'foo', 'value' => 'semaphore'], ['name' => 'bar', 'value' => 'semaphore']]], ['enabled' => false, 'resources' => ['foo' => ['flock', 'semaphore'], 'bar' => ['semaphore']]]];
|
||||||
|
}
|
||||||
|
|
||||||
protected static function getBundleDefaultConfig()
|
protected static function getBundleDefaultConfig()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
Reference in New Issue
Block a user