1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ElfSundae\BearyChat\Laravel\Jobs; |
4
|
|
|
|
5
|
|
|
use Illuminate\Bus\Queueable; |
6
|
|
|
use ElfSundae\BearyChat\Client; |
7
|
|
|
use ElfSundae\BearyChat\Message; |
8
|
|
|
use Illuminate\Queue\SerializesModels; |
9
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
10
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
11
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
12
|
|
|
|
13
|
|
|
class SendBearyChat implements ShouldQueue |
14
|
|
|
{ |
15
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* The BearyChat client. |
19
|
|
|
* |
20
|
|
|
* @var \ElfSundae\BearyChat\Client |
21
|
|
|
*/ |
22
|
|
|
protected $client; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The Message instance to be sent. |
26
|
|
|
* |
27
|
|
|
* @var \ElfSundae\BearyChat\Message |
28
|
|
|
*/ |
29
|
|
|
protected $message; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Create a new job instance. |
33
|
|
|
* |
34
|
|
|
* @param mixed $message |
35
|
|
|
*/ |
36
|
|
|
public function __construct($message = null) |
37
|
|
|
{ |
38
|
|
|
if ($message instanceof Message) { |
39
|
|
|
$this->message = $message; |
40
|
|
|
} elseif (! is_null($message)) { |
41
|
|
|
call_user_func_array([$this, 'content'], func_get_args()); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Set the BearyChat client. |
47
|
|
|
* |
48
|
|
|
* @param \ElfSundae\BearyChat\Client|string $client |
49
|
|
|
* @return $this |
50
|
|
|
*/ |
51
|
|
|
public function client($client) |
52
|
|
|
{ |
53
|
|
|
$this->client = $client instanceof Client ? $client : bearychat($client); |
54
|
|
|
|
55
|
|
|
if ($this->message) { |
56
|
|
|
$this->message->setClient($this->client); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Execute the job. |
64
|
|
|
* |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
public function handle() |
68
|
|
|
{ |
69
|
|
|
if (! $this->message->getClient()) { |
70
|
|
|
$this->message->setClient($this->client ?: bearychat()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$this->message->send(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Any unhandled methods will be sent to the Message instance. |
78
|
|
|
* |
79
|
|
|
* @param string $method |
80
|
|
|
* @param array $parameters |
81
|
|
|
* @return $this |
82
|
|
|
*/ |
83
|
|
|
public function __call($method, $parameters) |
84
|
|
|
{ |
85
|
|
|
if (! $this->message) { |
86
|
|
|
$this->message = new Message($this->client ?: bearychat()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
call_user_func_array([$this->message, $method], $parameters); |
90
|
|
|
|
91
|
|
|
return $this; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|