-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up how events are dispatched to not use old style jobs.
This maintains backwards compatibility by keeping around the old job class until the 5.5 release.
- Loading branch information
1 parent
d1a0842
commit 8c90e7f
Showing
5 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Illuminate\Events; | ||
|
||
use Illuminate\Container\Container; | ||
use Illuminate\Contracts\Queue\Job; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
class CallQueuedListener implements ShouldQueue | ||
{ | ||
use InteractsWithQueue; | ||
|
||
/** | ||
* The listener class name. | ||
* | ||
* @var string | ||
*/ | ||
public $class; | ||
|
||
/** | ||
* The listener method. | ||
* | ||
* @var string | ||
*/ | ||
public $method; | ||
|
||
/** | ||
* The data to be passed to the listener. | ||
* | ||
* @var string | ||
*/ | ||
public $data; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param string $class | ||
* @param string $method | ||
* @param string $data | ||
* @return void | ||
*/ | ||
public function __construct($class, $method, $data) | ||
{ | ||
$this->data = $data; | ||
$this->class = $class; | ||
$this->method = $method; | ||
} | ||
|
||
/** | ||
* Handle the queued job. | ||
* | ||
* @param \Illuminate\Container\Container $container | ||
* @return void | ||
*/ | ||
public function handle(Container $container) | ||
{ | ||
$handler = $this->setJobInstanceIfNecessary( | ||
$this->job, $container->make($this->class) | ||
); | ||
|
||
call_user_func_array( | ||
[$handler, $this->method], unserialize($this->data) | ||
); | ||
} | ||
|
||
/** | ||
* Set the job instance of the given class if necessary. | ||
* | ||
* @param \Illuminate\Contracts\Queue\Job $job | ||
* @param mixed $instance | ||
* @return mixed | ||
*/ | ||
protected function setJobInstanceIfNecessary(Job $job, $instance) | ||
{ | ||
if (in_array(InteractsWithQueue::class, class_uses_recursive(get_class($instance)))) { | ||
$instance->setJob($job); | ||
} | ||
|
||
return $instance; | ||
} | ||
|
||
/** | ||
* Call the failed method on the job instance. | ||
* | ||
* The event instance and the exception will be passed. | ||
* | ||
* @param \Exception $e | ||
* @return void | ||
*/ | ||
public function failed($e) | ||
{ | ||
$handler = Container::getInstance()->make($this->class); | ||
|
||
$parameters = array_merge(unserialize($this->data), [$e]); | ||
|
||
if (method_exists($handler, 'failed')) { | ||
call_user_func_array([$handler, 'failed'], $parameters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters