8000 gracefully handle missing event dispatchers · symfony/symfony@d4ae85f · GitHub
[go: up one dir, main page]

Skip to content

Commit d4ae85f

Browse files
committed
gracefully handle missing event dispatchers
1 parent 56fac41 commit d4ae85f

12 files changed

+82
-12
lines changed

src/Symfony/Component/Messenger/Middleware/SendMessageMiddleware.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ class SendMessageMiddleware implements MiddlewareInterface
3939
public function __construct(SendersLocatorInterface $sendersLocator, EventDispatcherInterface $eventDispatcher = null)
4040
{
4141
$this->sendersLocator = $sendersLocator;
42-
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
42+
43+
if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
44+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
45+
} else {
46+
$this->eventDispatcher = $eventDispatcher;
47+
}
48+
4349
$this->logger = new NullLogger();
4450
}
4551

src/Symfony/Component/Messenger/Worker.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ public function __construct(array $receivers, MessageBusInterface $bus, array $r
5252
$this->receivers = $receivers;
5353
$this->bus = $bus;
5454
$this->retryStrategies = $retryStrategies;
55-
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
55+
56+
if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
57+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
58+
} else {
59+
$this->eventDispatcher = $eventDispatcher;
60+
}
61+
5662
$this->logger = $logger;
5763
}
5864

src/Symfony/Component/Security/Core/Authorization/Voter/TraceableVoter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ class TraceableVoter implements VoterInterface
3131
public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher)
3232
{
3333
$this->voter = $voter;
34-
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
34+
35+
if (class_exists(LegacyEventDispatcherProxy::class)) {
36+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
37+
} else {
38+
$this->eventDispatcher = $eventDispatcher;
39+
}
3540
}
3641

3742
public function vote(TokenInterface $token, $subject, array $attributes)

src/Symfony/Component/Security/Guard/GuardAuthenticatorHandler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ class GuardAuthenticatorHandler
4646
public function __construct(TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher = null, array $statelessProviderKeys = [])
4747
{
4848
$this->tokenStorage = $tokenStorage;
49-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
49+
50+
if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
51+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
52+
} else {
53+
$this->dispatcher = $eventDispatcher;
54+
}
55+
5056
$this->statelessProviderKeys = $statelessProviderKeys;
5157
}
5258

src/Symfony/Component/Security/Http/Firewall/AbstractAuthenticationListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
9393
'require_previous_session' => true,
9494
], $options);
9595
$this->logger = $logger;
96-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
96+
97+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
98+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
99+
} else {
100+
$this->dispatcher = $dispatcher;
101+
}
102+
97103
$this->httpUtils = $httpUtils;
98104
}
99105

src/Symfony/Component/Security/Http/Firewall/AbstractPreAuthenticatedListener.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
5252
$this->authenticationManager = $authenticationManager;
5353
$this->providerKey = $providerKey;
5454
$this->logger = $logger;
55-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
55+
56+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
57+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
58+
} else {
59+
$this->dispatcher = $dispatcher;
60+
}
5661
}
5762

5863
/**

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ public function __construct(TokenStorageInterface $tokenStorage, iterable $userP
6666
$this->userProviders = $userProviders;
6767
$this->sessionKey = '_security_'.$contextKey;
6868
$this->logger = $logger;
69-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
69+
70+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
71+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
72+
} else {
73+
$this->dispatcher = $dispatcher;
74+
}
75+
7076
$this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class);
7177
}
7278

src/Symfony/Component/Security/Http/Firewall/RememberMeListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi
4949
$this->rememberMeServices = $rememberMeServices;
5050
$this->authenticationManager = $authenticationManager;
5151
$this->logger = $logger;
52-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
52+
53+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
54+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
55+
} else {
56+
$this->dispatcher = $dispatcher;
57+
}
58+
5359
$this->catchExceptions = $catchExceptions;
5460
$this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy;
5561
}

src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
6565
$this->providerKey = $providerKey;
6666
$this->simpleAuthenticator = $simpleAuthenticator;
6767
$this->logger = $logger;
68-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
68+
69+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
70+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
71+
} else {
72+
$this->dispatcher = $dispatcher;
73+
}
74+
6975
$this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class);
7076
}
7177

src/Symfony/Component/Security/Http/Firewall/SwitchUserListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt
7070
$this->usernameParameter = $usernameParameter;
7171
$this->role = $role;
7272
$this->logger = $logger;
73-
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
73+
74+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
75+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
76+
} else {
77+
$this->dispatcher = $dispatcher;
78+
}
79+
7480
$this->stateless = $stateless;
7581
}
7682

src/Symfony/Component/Security/Http/Firewall/UsernamePasswordJsonAuthenticationListener.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
6969
$this->successHandler = $successHandler;
7070
$this->failureHandler = $failureHandler;
7171
$this->logger = $logger;
72-
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
72+
73+
if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
74+
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
75+
} else {
76+
$this->eventDispatcher = $eventDispatcher;
77+
}
78+
7379
$this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options);
7480
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
7581
}

src/Symfony/Component/Workflow/Workflow.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public function __construct(Definition $definition, MarkingStoreInterface $marki
4343
{
4444
$this->definition = $definition;
4545
$this->markingStore = $markingStore ?: new MultipleStateMarkingStore();
46-
$this->dispatcher = null !== $dispatcher ? LegacyEventDispatcherProxy::decorate($dispatcher) : null;
46+
47+
if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
48+
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
49+
} else {
50+
$this->dispatcher = $dispatcher;
51+
}
52+
4753
$this->name = $name;
4854
}
4955

0 commit comments

Comments
 (0)
0