Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #54135 [Console] Add a way to use custom lock factory in lock…
…ableTrait (VincentLanglet) This PR was squashed before being merged into the 7.1 branch. Discussion ---------- [Console] Add a way to use custom lock factory in lockableTrait | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT The LockableTrait only use SemaphoreStore or FlockStore, but currently we cannot use MemcachedStore or RedisStore. When using a custom LockFactory everywhere in the codebase, it would be useful to chose if the commande need a server-related store or not. I'm not sure if I have a way to provide autowire to the `setLockFactory` method without introducing a BC break for people who rely on the fact that the LockableTrait use a different LockFactory than the one configured the `framework.lock` dsn. Commits ------- 28c73f8 [Console] Add a way to use custom lock factory in lockableTrait
- Loading branch information
Showing
3 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Symfony/Component/Console/Tests/Fixtures/FooLock3Command.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Command\LockableTrait; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Lock\LockFactory; | ||
|
||
class FooLock3Command extends Command | ||
{ | ||
use LockableTrait; | ||
|
||
public function __construct(LockFactory $lockFactory) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->lockFactory = $lockFactory; | ||
} | ||
|
||
protected function configure(): void | ||
{ | ||
$this->setName('foo:lock3'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
if (!$this->lock()) { | ||
return 1; | ||
} | ||
|
||
$this->release(); | ||
|
||
return 2; | ||
} | ||
} |