1
|
<?php
|
2
|
|
3
|
namespace Illuminate\Events;
|
4
|
|
5
|
use Illuminate\Contracts\Queue\Job;
|
6
|
use Illuminate\Contracts\Container\Container;
|
7
|
|
8
|
class CallQueuedHandler
|
9
|
{
|
10
|
/**
|
11
|
* The container instance.
|
12
|
*
|
13
|
* @var \Illuminate\Contracts\Container\Container
|
14
|
*/
|
15
|
protected $container;
|
16
|
|
17
|
/**
|
18
|
* Create a new job instance.
|
19
|
*
|
20
|
* @param \Illuminate\Contracts\Container\Container $container
|
21
|
* @return void
|
22
|
*/
|
23
|
public function __construct(Container $container)
|
24
|
{
|
25
|
$this->container = $container;
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Handle the queued job.
|
30
|
*
|
31
|
* @param \Illuminate\Contracts\Queue\Job $job
|
32
|
* @param array $data
|
33
|
* @return void
|
34
|
*/
|
35
|
public function call(Job $job, array $data)
|
36
|
{
|
37
|
$handler = $this->setJobInstanceIfNecessary(
|
38
|
$job, $this->container->make($data['class'])
|
39
|
);
|
40
|
|
41
|
call_user_func_array(
|
42
|
[$handler, $data['method']], unserialize($data['data'])
|
43
|
);
|
44
|
|
45
|
if (! $job->isDeletedOrReleased()) {
|
46
|
$job->delete();
|
47
|
}
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* Set the job instance of the given class if necessary.
|
52
|
*
|
53
|
* @param \Illuminate\Contracts\Queue\Job $job
|
54
|
* @param mixed $instance
|
55
|
* @return mixed
|
56
|
*/
|
57
|
protected function setJobInstanceIfNecessary(Job $job, $instance)
|
58
|
{
|
59
|
if (in_array('Illuminate\Queue\InteractsWithQueue', class_uses_recursive(get_class($instance)))) {
|
60
|
$instance->setJob($job);
|
61
|
}
|
62
|
|
63
|
return $instance;
|
64
|
}
|
65
|
|
66
|
/**
|
67
|
* Call the failed method on the job instance.
|
68
|
*
|
69
|
* @param array $data
|
70
|
* @return void
|
71
|
*/
|
72
|
public function failed(array $data)
|
73
|
{
|
74
|
$handler = $this->container->make($data['class']);
|
75
|
|
76
|
if (method_exists($handler, 'failed')) {
|
77
|
call_user_func_array([$handler, 'failed'], unserialize($data['data']));
|
78
|
}
|
79
|
}
|
80
|
}
|