Skip to content

Commit 5548611

Browse files
bug #48119 [FrameworkBundle][Lock] Allow to disable lock without defining a resource (MatTheCat)
This PR was merged into the 4.4 branch. Discussion ---------- [FrameworkBundle][Lock] Allow to disable lock without defining a resource | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A While answering #48115 I noticed a resource is mandatory in lock’s configuration even if it’s disabled because of `requiresAtLeastOneElement`. I replaced it with a validation rule which takes `enabled` into account. Commits ------- 0aad8c8 Allow to disable lock without defining a resource
2 parents ad0e25f + 0aad8c8 commit 5548611

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,12 +1117,15 @@ private function addLockSection(ArrayNodeDefinition $rootNode)
11171117
})
11181118
->end()
11191119
->addDefaultsIfNotSet()
1120+
->validate()
1121+
->ifTrue(static function (array $config) { return $config['enabled'] && !$config['resources']; })
1122+
->thenInvalid('At least one resource must be defined.')
1123+
->end()
11201124
->fixXmlConfig('resource')
11211125
->children()
11221126
->arrayNode('resources')
11231127
->normalizeKeys(false)
11241128
->useAttributeAsKey('name')
1125-
->requiresAtLeastOneElement()
11261129
->defaultValue(['default' => [class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphore' : 'flock']])
11271130
->beforeNormalization()
11281131
->ifString()->then(function ($v) { return ['default' => $v]; })

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,31 @@ public function testItErrorsWhenDefaultBusDoesNotExist()
378378
]);
379379
}
380380

381+
public function testLockCanBeDisabled()
382+
{
383+
$processor = new Processor();
384+
$configuration = new Configuration(true);
385+
386+
$config = $processor->processConfiguration($configuration, [
387+
['lock' => ['enabled' => false]],
388+
]);
389+
390+
$this->assertFalse($config['lock']['enabled']);
391+
}
392+
393+
public function testEnabledLockNeedsResources()
394+
{
395+
$processor = new Processor();
396+
$configuration = new Configuration(true);
397+
398+
$this->expectException(InvalidConfigurationException::class);
399+
$this->expectExceptionMessage('Invalid configuration for path "framework.lock": At least one resource must be defined.');
400+
401+
$processor->processConfiguration($configuration, [
402+
['lock' => ['enabled' => true]],
403+
]);
404+
}
405+
381406
protected static function getBundleDefaultConfig()
382407
{
383408
return [

0 commit comments

Comments
 (0)
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