Skip to content

Commit

Permalink
bug #34854 [Messenger] gracefully handle missing event dispatchers (x…
Browse files Browse the repository at this point in the history
…abbuh)

This PR was merged into the 4.3 branch.

Discussion
----------

[Messenger] gracefully handle missing event dispatchers

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34852
| License       | MIT
| Doc PR        |

Commits
-------

d4ae85f gracefully handle missing event dispatchers
  • Loading branch information
fabpot committed Dec 7, 2019
2 parents 2ac5609 + d4ae85f commit 9a025b4
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 12 deletions.
Expand Up @@ -39,7 +39,13 @@ class SendMessageMiddleware implements MiddlewareInterface
public function __construct(SendersLocatorInterface $sendersLocator, EventDispatcherInterface $eventDispatcher = null)
{
$this->sendersLocator = $sendersLocator;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
} else {
$this->eventDispatcher = $eventDispatcher;
}

$this->logger = new NullLogger();
}

Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Messenger/Worker.php
Expand Up @@ -52,7 +52,13 @@ public function __construct(array $receivers, MessageBusInterface $bus, array $r
$this->receivers = $receivers;
$this->bus = $bus;
$this->retryStrategies = $retryStrategies;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
} else {
$this->eventDispatcher = $eventDispatcher;
}

$this->logger = $logger;
}

Expand Down
Expand Up @@ -31,7 +31,12 @@ class TraceableVoter implements VoterInterface
public function __construct(VoterInterface $voter, EventDispatcherInterface $eventDispatcher)
{
$this->voter = $voter;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

if (class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
} else {
$this->eventDispatcher = $eventDispatcher;
}
}

public function vote(TokenInterface $token, $subject, array $attributes)
Expand Down
Expand Up @@ -46,7 +46,13 @@ class GuardAuthenticatorHandler
public function __construct(TokenStorageInterface $tokenStorage, EventDispatcherInterface $eventDispatcher = null, array $statelessProviderKeys = [])
{
$this->tokenStorage = $tokenStorage;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
} else {
$this->dispatcher = $eventDispatcher;
}

$this->statelessProviderKeys = $statelessProviderKeys;
}

Expand Down
Expand Up @@ -93,7 +93,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
'require_previous_session' => true,
], $options);
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->httpUtils = $httpUtils;
}

Expand Down
Expand Up @@ -52,7 +52,12 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
$this->authenticationManager = $authenticationManager;
$this->providerKey = $providerKey;
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}
}

/**
Expand Down
Expand Up @@ -66,7 +66,13 @@ public function __construct(TokenStorageInterface $tokenStorage, iterable $userP
$this->userProviders = $userProviders;
$this->sessionKey = '_security_'.$contextKey;
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class);
}

Expand Down
Expand Up @@ -49,7 +49,13 @@ public function __construct(TokenStorageInterface $tokenStorage, RememberMeServi
$this->rememberMeServices = $rememberMeServices;
$this->authenticationManager = $authenticationManager;
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->catchExceptions = $catchExceptions;
$this->sessionStrategy = null === $sessionStrategy ? new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE) : $sessionStrategy;
}
Expand Down
Expand Up @@ -65,7 +65,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
$this->providerKey = $providerKey;
$this->simpleAuthenticator = $simpleAuthenticator;
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->trustResolver = $trustResolver ?: new AuthenticationTrustResolver(AnonymousToken::class, RememberMeToken::class);
}

Expand Down
Expand Up @@ -70,7 +70,13 @@ public function __construct(TokenStorageInterface $tokenStorage, UserProviderInt
$this->usernameParameter = $usernameParameter;
$this->role = $role;
$this->logger = $logger;
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->stateless = $stateless;
}

Expand Down
Expand Up @@ -69,7 +69,13 @@ public function __construct(TokenStorageInterface $tokenStorage, AuthenticationM
$this->successHandler = $successHandler;
$this->failureHandler = $failureHandler;
$this->logger = $logger;
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);

if (null !== $eventDispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher);
} else {
$this->eventDispatcher = $eventDispatcher;
}

$this->options = array_merge(['username_path' => 'username', 'password_path' => 'password'], $options);
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/Workflow/Workflow.php
Expand Up @@ -43,7 +43,13 @@ public function __construct(Definition $definition, MarkingStoreInterface $marki
{
$this->definition = $definition;
$this->markingStore = $markingStore ?: new MultipleStateMarkingStore();
$this->dispatcher = null !== $dispatcher ? LegacyEventDispatcherProxy::decorate($dispatcher) : null;

if (null !== $dispatcher && class_exists(LegacyEventDispatcherProxy::class)) {
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
} else {
$this->dispatcher = $dispatcher;
}

$this->name = $name;
}

Expand Down

0 comments on commit 9a025b4

Please sign in to comment.