From 8a7e84439bfda3f119521254c91d6dec07a25fd4 Mon Sep 17 00:00:00 2001 From: Michael Kardakov Date: Thu, 27 Jun 2019 17:03:16 +0300 Subject: [PATCH 1/2] Fix deprecation errors at Symfony 4+ --- CHANGELOG | 3 +++ Event/AMQPEvent.php | 2 +- RabbitMq/BaseAmqp.php | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5939d358..52059765 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,6 @@ +- 2019-06-27 + * Fix Deprecation errors with Symfony 4+ + - 2017-01-22 * Add `graceful_max_execution_timeout` diff --git a/Event/AMQPEvent.php b/Event/AMQPEvent.php index 3c9dee11..ab6b2180 100644 --- a/Event/AMQPEvent.php +++ b/Event/AMQPEvent.php @@ -4,7 +4,7 @@ use OldSound\RabbitMqBundle\RabbitMq\Consumer; use PhpAmqpLib\Message\AMQPMessage; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; /** * Class AMQPEvent diff --git a/RabbitMq/BaseAmqp.php b/RabbitMq/BaseAmqp.php index 27b37c10..c9418360 100644 --- a/RabbitMq/BaseAmqp.php +++ b/RabbitMq/BaseAmqp.php @@ -8,6 +8,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; abstract class BaseAmqp { @@ -273,7 +274,9 @@ protected function queueBind($queue, $exchange, $routing_key) */ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; + $this->eventDispatcher = class_exists('Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy') ? + LegacyEventDispatcherProxy::decorate($eventDispatcher) : + $eventDispatcher; return $this; } From 5c9ecb796299c34e29dbe5edc8bd6f49c311aedb Mon Sep 17 00:00:00 2001 From: Michael Kardakov Date: Thu, 27 Jun 2019 17:31:02 +0300 Subject: [PATCH 2/2] Fix deprecation errors at Symfony 4+ --- RabbitMq/BaseAmqp.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/RabbitMq/BaseAmqp.php b/RabbitMq/BaseAmqp.php index c9418360..60982ca2 100644 --- a/RabbitMq/BaseAmqp.php +++ b/RabbitMq/BaseAmqp.php @@ -8,7 +8,7 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContactsEventDispatcherInterface; abstract class BaseAmqp { @@ -274,9 +274,7 @@ protected function queueBind($queue, $exchange, $routing_key) */ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = class_exists('Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy') ? - LegacyEventDispatcherProxy::decorate($eventDispatcher) : - $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; return $this; } @@ -288,10 +286,13 @@ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) protected function dispatchEvent($eventName, AMQPEvent $event) { if ($this->getEventDispatcher()) { - $this->getEventDispatcher()->dispatch( - $eventName, - $event - ); + if ($this->getEventDispatcher() instanceof ContactsEventDispatcherInterface) { + $this->getEventDispatcher() + ->dispatch($event, $eventName); + } else { + $this->getEventDispatcher() + ->dispatch($eventName, $event); + } } }