Skip to content

Commit e6304b2

Browse files
committed
feature #38593 [Lock][Semaphore] Add Factory::createFromKey and deprecate lock.store services (jderusse)
This PR was merged into the 5.x branch. Discussion ---------- [Lock][Semaphore] Add Factory::createFromKey and deprecate lock.store services I| Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | / | License | MIT | Doc PR | todo The `lock` service and aliases have been deprecated in #38576. This PR also deprecate the `lock.store` service and aliases. People should always inject the factory into their services, except for one scenario: When they want building the `Lock` manually because they want to keep the key. This scenario require declaring `lock.store` service and `PersisingStoreInterface` aliases. This could be avoided if people had a method to create a lock from a given key. This PR adds a `LockFactory::createFromKey()` method and deprecate all `lock.store` services I also updated the Semaphore component for consistency, and helping people to only inject the SemahoreFactory. nb: use cases for serializing the keys: - Netflix allows only 5 users of the same family at the same time. - An holiday apartment rental avoid users putting the same apartment in the basket - ... Commits ------- 91fa3e311d Deprecate lock.store aliases
2 parents df24ffc + 67281f8 commit e6304b2

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CHANGELOG
1414
* added `assertCheckboxChecked()` and `assertCheckboxNotChecked()` in `WebTestCase`
1515
* added `assertFormValue()` and `assertNoFormValue()` in `WebTestCase`
1616
* Added "--as-tree=3" option to `translation:update` command to dump messages as a tree-like structure. The given value defines the level where to switch to inline YAML
17-
* Deprecated the `lock.RESOURCE_NAME` service and the `lock` and `LockInterface` aliases, use `lock.RESOURCE_NAME.factory`, `lock.factory` or `LockFactory` instead.
17+
* Deprecated the `lock.RESOURCE_NAME` and `lock.RESOURCE_NAME.store` services and the `lock`, `LockInterface`, `lock.store` and `PersistingStoreInterface` aliases, use `lock.RESOURCE_NAME.factory`, `lock.factory` or `LockFactory` instead.
1818

1919
5.1.0
2020
-----

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,14 +1674,15 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
16741674
if (\count($storeDefinitions) > 1) {
16751675
$combinedDefinition = new ChildDefinition('lock.store.combined.abstract');
16761676
$combinedDefinition->replaceArgument(0, $storeDefinitions);
1677-
$container->setDefinition('lock.'.$resourceName.'.store', $combinedDefinition);
1677+
$container->setDefinition('lock.'.$resourceName.'.store', $combinedDefinition)->setDeprecated('symfony/framework-bundle', '5.2', 'The "%service_id%" service is deprecated, use "lock.'.$resourceName.'.factory" instead.');
1678+
$container->setDefinition($storeDefinitionId = '.lock.'.$resourceName.'.store.'.$container->hash($resourceStores), $combinedDefinition);
16781679
} else {
1679-
$container->setAlias('lock.'.$resourceName.'.store', new Alias((string) $storeDefinitions[0], false));
1680+
$container->setAlias('lock.'.$resourceName.'.store', (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "lock.'.$resourceName.'.factory" instead.'));
16801681
}
16811682

16821683
// Generate factories for each resource
16831684
$factoryDefinition = new ChildDefinition('lock.factory.abstract');
1684-
$factoryDefinition->replaceArgument(0, new Reference('lock.'.$resourceName.'.store'));
1685+
$factoryDefinition->replaceArgument(0, new Reference($storeDefinitionId));
16851686
$container->setDefinition('lock.'.$resourceName.'.factory', $factoryDefinition);
16861687

16871688
// Generate services for lock instances
@@ -1693,14 +1694,14 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
16931694

16941695
// provide alias for default resource
16951696
if ('default' === $resourceName) {
1696-
$container->setAlias('lock.store', new Alias('lock.'.$resourceName.'.store', false));
1697+
$container->setAlias('lock.store', (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
16971698
$container->setAlias('lock.factory', new Alias('lock.'.$resourceName.'.factory', false));
16981699
$container->setAlias('lock', (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "lock.factory" instead.'));
1699-
$container->setAlias(PersistingStoreInterface::class, new Alias('lock.store', false));
1700+
$container->setAlias(PersistingStoreInterface::class, (new Alias($storeDefinitionId, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
17001701
$container->setAlias(LockFactory::class, new Alias('lock.factory', false));
17011702
$container->setAlias(LockInterface::class, (new Alias('lock.'.$resourceName, false))->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.'" instead.'));
17021703
} else {
1703-
$container->registerAliasForArgument('lock.'.$resourceName.'.store', PersistingStoreInterface::class, $resourceName.'.lock.store');
1704+
$container->registerAliasForArgument($storeDefinitionId, PersistingStoreInterface::class, $resourceName.'.lock.store')->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' '.$resourceName.'LockFactory" instead.');
17041705
$container->registerAliasForArgument('lock.'.$resourceName.'.factory', LockFactory::class, $resourceName.'.lock.factory');
17051706
$container->registerAliasForArgument('lock.'.$resourceName, LockInterface::class, $resourceName.'.lock')->setDeprecated('symfony/framework-bundle', '5.2', 'The "%alias_id%" alias is deprecated, use "'.LockFactory::class.' $'.$resourceName.'LockFactory" instead.');
17061707
}

0 commit comments

Comments
 (0)