-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Allow user to specify folder for flock #26923
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
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.
looks like a good idea to me
ping @jderusse for 2nd review
what about adding some tests?
@@ -1374,8 +1374,18 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | ||
foreach ($resourceStores as $storeDsn) { | ||
$storeDsn = $container->resolveEnvPlaceholders($storeDsn, null, $usedEnvs); | ||
switch (true) { | ||
case 'flock' === $storeDsn: |
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.
I think we should keep this case, and add a new one after
@@ -1374,8 +1374,18 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | ||
foreach ($resourceStores as $storeDsn) { | ||
$storeDsn = $container->resolveEnvPlaceholders($storeDsn, null, $usedEnvs); | ||
switch (true) { | ||
case 'flock' === $storeDsn: | ||
$storeDefinition = new Reference('lock.store.flock'); | ||
case 0 === strpos($storeDsn, 'flock'): |
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.
case 0 === strpos($storeDsn, 'flock://'):
+ substr instead of str_replace below
|
||
if ($isMatched) { | ||
$storeDefinition = new Definition(FlockStore::class); | ||
$storeDefinition->setPublic(false); |
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.
not required anymore, this is the default since 4.0
$storeDefinition = new Definition(FlockStore::class); | ||
$storeDefinition->setPublic(false); | ||
$storeDefinition->setArguments(array($flockPath)); | ||
$container->setDefinition($storeDefinitionId = 'lock.flock.store.'.$container->hash($storeDsn), $storeDefinition); |
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.
anticipating for #26921, the service name should start with a dot
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.
I'd suggest this:
$storeDefinitionId = '.lock.flock.store.'.$container->hash($storeDsn);
$container->register($storeDefinitionId, FlockStore::class)->addArgument($flockPath);
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.
Great idea, I like the use of DSN for such purpose.
Nothing to add to @nicolas-grekas 's comments :)
updated pr. |
@@ -1377,6 +1377,14 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont | ||
case 'flock' === $storeDsn: | ||
$storeDefinition = new Reference('lock.store.flock'); | ||
break; | ||
case 0 === strpos($storeDsn, 'flock'): |
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.
'flock://'
case 0 === strpos($storeDsn, 'flock'): | ||
$flockPath = substr($storeDsn, 8); | ||
|
||
$storeDefinitionId = 'lock.flock.store.'.$container->hash($storeDsn); |
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.
'.lock.flock.store.'.$container->hash($storeDsn);
as per @nicolas-grekas 's comment
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.
Can someone enlighten me about purpose of the starting dot?
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.
up |
see fabbot failure :) |
$flockPath = substr($storeDsn, 8); | ||
|
||
$storeDefinitionId = '.lock.flock.store.'.$container->hash($storeDsn); | ||
$container->register($storeDefinitionId, FlockStore::class)->addArgument($flockPath); |
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.
missing use
statement for the FlockStore
class
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
Is there anything else I forgot to fix? |
$storeDefinitionId = '.lock.flock.store.'.$container->hash($storeDsn); | ||
$container->register($storeDefinitionId, FlockStore::class)->addArgument($flockPath); | ||
|
||
$storeDefinition = new Reference($storeDefinitionId); |
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.
Do we need the reference? I mean if I don't miss anything, we do not reuse it anyway, so something like this should work the same:
$flockPath = substr($storeDsn, 8);
$storeDefinitionId = '.lock.flock.store.'.$container->hash($storeDsn);
$storeDefinition = $container->register($storeDefinitionId, FlockStore::class)->addArgument($flockPath);
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 can be said for both 'flock' and 'semaphore' cases. But I'm not sure that this PR is correct place for such refactoring. Besides '$storeDefinitions' already contains 'Reference' objects so it would be not cool to add strings or non-Reference type
up |
Thank you @MaksSlesarenko. |
…ck (MaksSlesarenko) This PR was merged into the 4.2-dev branch. Discussion ---------- [FrameworkBundle] Allow user to specify folder for flock | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | License | MIT | Doc PR | In case multiple applications running on same server allow user to specify folder for flock example: ``` framework: lock:` 'flock://var/flock' # var/flock will be provided as path to flock constructor lock: 'flock:///var/flock' # /var/flock will be provided as path to flock constructor lock: flock # works as usual, null is provided to constructor and system temp folder is used ``` Commits ------- 244d762 added ability to specify folder for flock
…rence (HypeMC) This PR was submitted for the 4.2 branch but it was squashed and merged into the 4.3 branch instead (closes #11466). Discussion ---------- Add flock:// option to framework lock configuration reference Fixes #9779 & extends #11465 . Documents the `flock://` option which was added with symfony/symfony#26923 . **NOTE 1**: The xml configuration doesn't currently work, see symfony/symfony#31197 **NOTE 2**: This PR has all the changes that #11465 has plus some symfony 4.2 specific additions, so #11465 should probably be merged first. Commits ------- d9125fd Add flock:// option to framework lock configuration reference
In case multiple applications running on same server allow user to specify folder for flock
example: