From 19d6c796a746300de66cf07fd799a718aa1a0739 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Fri, 7 Jul 2017 17:36:39 +0200 Subject: [PATCH 1/3] add a method to determine if handler should be push to queue --- src/Illuminate/Events/Dispatcher.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index 0d1d2180b916..d10fb5debedd 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -426,12 +426,30 @@ protected function handlerShouldBeQueued($class) protected function createQueuedHandlerCallable($class, $method) { return function () use ($class, $method) { - $this->queueHandler($class, $method, array_map(function ($a) { + $arguments = array_map(function ($a) { return is_object($a) ? clone $a : $a; - }, func_get_args())); + }, func_get_args()); + + if ($this->mayQueueHandler($class, $arguments)) { + $this->queueHandler($class, $method, $arguments);; + } }; } + /** + * Determine if the event handler may be pushed to queue. + * + * @param string $class + * @param array $arguments + * @return bool + */ + protected function mayQueueHandler($class, $arguments) + { + return ! method_exists($class, 'shouldPushToQueue') ? false + : (new ReflectionClass($class))->newInstanceWithoutConstructor() + ->shouldPushToQueue($arguments[0]); + } + /** * Queue the handler class. * From 3e2e68117893dba7ec75892c1e8c6adcb5378c2d Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Fri, 7 Jul 2017 17:40:43 +0200 Subject: [PATCH 2/3] fix style --- src/Illuminate/Events/Dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index d10fb5debedd..e87cf829228b 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -431,7 +431,7 @@ protected function createQueuedHandlerCallable($class, $method) }, func_get_args()); if ($this->mayQueueHandler($class, $arguments)) { - $this->queueHandler($class, $method, $arguments);; + $this->queueHandler($class, $method, $arguments); } }; } From a2910f27e6a8312f627e760fe13c2200e058f14e Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Fri, 7 Jul 2017 17:41:18 +0200 Subject: [PATCH 3/3] fix logic --- src/Illuminate/Events/Dispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Events/Dispatcher.php b/src/Illuminate/Events/Dispatcher.php index e87cf829228b..a95f5f110167 100755 --- a/src/Illuminate/Events/Dispatcher.php +++ b/src/Illuminate/Events/Dispatcher.php @@ -445,7 +445,7 @@ protected function createQueuedHandlerCallable($class, $method) */ protected function mayQueueHandler($class, $arguments) { - return ! method_exists($class, 'shouldPushToQueue') ? false + return ! method_exists($class, 'shouldPushToQueue') ? true : (new ReflectionClass($class))->newInstanceWithoutConstructor() ->shouldPushToQueue($arguments[0]); }