Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a77765

Browse filesBrowse files
Feedback
1 parent e8b1f4f commit 9a77765
Copy full SHA for 9a77765

File tree

3 files changed

+23
-31
lines changed
Filter options

3 files changed

+23
-31
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,7 +1987,7 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
19871987
{
19881988
$loader->load('lock.php');
19891989

1990-
if (!class_exists(LockMiddleware::class)) {
1990+
if (!class_exists(LockMiddleware::class) || !class_exists(LockFactory::class)) {
19911991
$container->removeDefinition('messenger.middleware.lock_middleware');
19921992
}
19931993

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
->set('messenger.middleware.lock_middleware', LockMiddleware::class)
9191
->args([
92-
service('lock.factory')->nullOnInvalid(),
92+
service('lock.factory'),
9393
])
9494

9595
->set('messenger.middleware.add_bus_name_stamp_middleware', AddBusNameStampMiddleware::class)

‎src/Symfony/Component/Messenger/Middleware/LockMiddleware.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Middleware/LockMiddleware.php
+21-29Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,40 @@
2121

2222
final class LockMiddleware implements MiddlewareInterface
2323
{
24-
private ?LockFactory $lockFactory = null;
24+
private LockFactory $lockFactory;
2525

26-
public function __construct(
27-
?LockFactory $lockFactory,
28-
) {
26+
public function __construct(LockFactory $lockFactory)
27+
{
2928
$this->lockFactory = $lockFactory;
3029
}
3130

3231
public function handle(Envelope $envelope, StackInterface $stack): Envelope
3332
{
34-
if (null === $this->lockFactory) {
33+
$message = $envelope->getMessage();
34+
if (!$message instanceof LockableMessageInterface) {
3535
return $stack->next()->handle($envelope, $stack);
3636
}
3737

38-
$message = $envelope->getMessage();
39-
4038
if (null === $envelope->last(ReceivedStamp::class)) {
41-
if ($message instanceof LockableMessageInterface) {
42-
// If we're trying to dispatch a lockable message.
43-
$keyResource = $message->getKey();
44-
45-
if (null !== $keyResource) {
46-
$key = new Key($keyResource);
39+
// If we're trying to dispatch a lockable message.
40+
$keyResource = $message->getKey();
4741

48-
// The acquire call must be done before stamping the message
49-
// in order to have the full state of the key in the stamp.
50-
$lock = $message instanceof TTLAwareLockableMessageInterface
51-
? $this->lockFactory->createLockFromKey($key, $message->getTTL(), autoRelease: false)
52-
: $this->lockFactory->createLockFromKey($key, autoRelease: false);
42+
if (null !== $keyResource) {
43+
$key = new Key($keyResource);
5344

54-
if (!$lock->acquire()) {
55-
return $envelope;
56-
}
45+
// The acquire call must be done before stamping the message
46+
// in order to have the full state of the key in the stamp.
47+
$lock = $message instanceof TTLAwareLockableMessageInterface
48+
? $this->lockFactory->createLockFromKey($key, $message->getTTL(), autoRelease: false)
49+
: $this->lockFactory->createLockFromKey($key, autoRelease: false);
5750

58-
// The acquire call must be done before stamping the message
59-
// in order to have the full state of the key in the stamp.
60-
$envelope = $envelope->with(new LockStamp($key, $message->shouldBeReleasedBeforeHandlerCall()));
51+
if (!$lock->acquire()) {
52+
return $envelope;
6153
}
54+
55+
// The acquire call must be done before stamping the message
56+
// in order to have the full state of the key in the stamp.
57+
$envelope = $envelope->with(new LockStamp($key, $message->shouldBeReleasedBeforeHandlerCall()));
6258
}
6359
} else {
6460
$this->releaseLock($envelope, true);
@@ -80,11 +76,7 @@ private function releaseLock(Envelope $envelope, bool $beforeHandlerCall): void
8076
{
8177
$stamp = $envelope->last(LockStamp::class);
8278
if ($stamp instanceof LockStamp && $stamp->shouldBeReleasedBeforHandlerCall() === $beforeHandlerCall) {
83-
$message = $envelope->getMessage();
84-
$lock = $message instanceof TTLAwareLockableMessageInterface
85-
? $this->lockFactory->createLockFromKey($stamp->getKey(), $message->getTTL(), autoRelease: false)
86-
: $this->lockFactory->createLockFromKey($stamp->getKey(), autoRelease: false);
87-
$lock->release();
79+
$this->lockFactory->createLockFromKey($stamp->getKey())->release();
8880
}
8981
}
9082
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.