-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add ability to use existing service as lock/semaphore resource #58249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -2004,6 +2004,9 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | |||
$storeDefinitions = []; | |||
foreach ($resourceStores as $resourceStore) { | |||
$storeDsn = $container->resolveEnvPlaceholders($resourceStore, null, $usedEnvs); | |||
if (!($usedEnvs || preg_match('#^[a-z]++://#', $resourceStore))) { | |||
$resourceStore = new Reference($resourceStore); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Lines 1230 to 1235 in 44395ab
} | |
$container->resolveEnvPlaceholders($config['handler_id'], null, $usedEnvs); | |
if ($usedEnvs || preg_match('#^[a-z]++://#', $config['handler_id'])) { | |
$id = '.cache_connection.'.ContainerBuilder::hash($config['handler_id']); | |
</xsd:sequence> | ||
<xsd:attribute name="enabled" type="xsd:boolean" /> | ||
<xsd:attribute name="resource" type="xsd:string" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why allowing a resource attribute here ? this does not make to me: we still need a name for the lock being registered, so <framework:resource name="my_lock">my_service</framework:resource>
is still the expected XML format to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same for semaphore of course
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof This is the equivalent of doing:
framework:
lock: dsn-or-service
If it's a string, the default
name is used:
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
Lines 1392 to 1394 in 4e70834
->beforeNormalization() | |
->ifString()->then(fn ($v) => ['default' => $v]) | |
->end() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the XML schema allows providing both the attribute and child elements, which would do weird stuff. I'd rather keep the clean XML schema as we have right now, even though it does not support one of the shortcut notation.
If someone is using XML configuration file, they will not complain to us that their configuration is too verbose due to that missing shortcut, as using XML in itself would be responsible for a lot more verbosity. Projects using XML configuration file generally do it to benefit from the XML schema.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c2a12b4
to
34e5112
Compare
…aphore config (HypeMC) This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Finish incomplete tests for lock & semaphore config | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT I noticed this while working on #58249. Basically, the test files were partially added but never used, so the tests were incomplete. ~Also, there's a bug in the schema, as the configuration in those files didn't work.~ Commits ------- 0574c86 [FrameworkBundle] Fix schema & finish incomplete tests for lock & semaphore config
@@ -2004,6 +2004,9 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | |||
$storeDefinitions = []; | |||
foreach ($resourceStores as $resourceStore) { | |||
$storeDsn = $container->resolveEnvPlaceholders($resourceStore, null, $usedEnvs); | |||
if (!($usedEnvs || preg_match('#^[a-z]++://#', $resourceStore))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should be enough IMHO:
if (!($usedEnvs || preg_match('#^[a-z]++://#', $resourceStore))) { | |
if (!$usedEnvs && !str_contains($resourceStore, '://')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, I've also changed it for the session handler config https://github.com/symfony/symfony/compare/34e5112e9afaf2ef4a9fb348a90b8bfeae71c6db..f53ef173a29e4921f5661369391e30ae980a7b3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
34e5112
to
f53ef17
Compare
f53ef17
to
e91d7aa
Compare
e91d7aa
to
670ee5d
Compare
Thank you @HypeMC. |
@@ -2004,6 +2004,9 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | |||
$storeDefinitions = []; | |||
foreach ($resourceStores as $resourceStore) { | |||
$storeDsn = $container->resolveEnvPlaceholders($resourceStore, null, $usedEnvs); | |||
if (!$usedEnvs && !str_contains($resourceStore, '://')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks BC in some use cases, like doctrine-bundle tests revealed https://github.com/doctrine/DoctrineBundle/actions/runs/10976729897/job/30477816481
…vice IDs (HypeMC) This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle][Lock] Fix certain DSNs identified as service IDs | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #58249 (comment) | License | MIT Follow up to #58249 The first PR introduced a BC break, as lock DSNs can also be in the following formats: ```yaml framework: lock: 'flock' lock: 'semaphore' lock: 'in-memory' lock: 'mysql:host=127.0.0.1;dbname=app' lock: 'pgsql:host=127.0.0.1;dbname=app' lock: 'pgsql+advisory:host=127.0.0.1;dbname=app' lock: 'sqlsrv:server=127.0.0.1;Database=app' lock: 'oci:host=127.0.0.1;dbname=app' ``` This PR introduces two changes: 1. The framework bundle now treats any string containing a `:` as a DSN, instead of only those with `://` 2. `flock`, `semaphore`, and `in-memory` are now treated as special cases Commits ------- 9abfbe0 [FrameworkBundle][Lock] Fix certain DSNs identified as service IDs
…vice IDs (HypeMC) This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle][Lock] Fix certain DSNs identified as service IDs | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix symfony/symfony#58249 (comment) | License | MIT Follow up to #58249 The first PR introduced a BC break, as lock DSNs can also be in the following formats: ```yaml framework: lock: 'flock' lock: 'semaphore' lock: 'in-memory' lock: 'mysql:host=127.0.0.1;dbname=app' lock: 'pgsql:host=127.0.0.1;dbname=app' lock: 'pgsql+advisory:host=127.0.0.1;dbname=app' lock: 'sqlsrv:server=127.0.0.1;Database=app' lock: 'oci:host=127.0.0.1;dbname=app' ``` This PR introduces two changes: 1. The framework bundle now treats any string containing a `:` as a DSN, instead of only those with `://` 2. `flock`, `semaphore`, and `in-memory` are now treated as special cases Commits ------- 9abfbe056d [FrameworkBundle][Lock] Fix certain DSNs identified as service IDs
Contains #58250
Currently, it's not possible to set an existing service as the lock/semaphore resource via the config, even though both factories support this functionality, eg:
symfony/src/Symfony/Component/Lock/Store/StoreFactory.php
Lines 27 to 36 in 44395ab