Skip to content

Commit

Permalink
Merge branch 'shouldPushToQueue' of https://github.com/themsaid/frame…
Browse files Browse the repository at this point in the history
…work into themsaid-shouldPushToQueue
  • Loading branch information
taylorotwell committed Jul 8, 2017
2 parents fc33b1a + a2910f2 commit ab7c826
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') ? true
: (new ReflectionClass($class))->newInstanceWithoutConstructor()
->shouldPushToQueue($arguments[0]);
}

/**
* Queue the handler class.
*
Expand Down

0 comments on commit ab7c826

Please sign in to comment.