1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Interfax; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Arr; |
6
|
|
|
|
7
|
|
|
class InterfaxMessage |
8
|
|
|
{ |
9
|
|
|
protected $files; |
10
|
|
|
protected $stream; |
11
|
|
|
protected $filename; |
12
|
|
|
protected $method; |
13
|
|
|
protected $statusCheck = false; |
14
|
|
|
public $user; |
15
|
|
|
|
16
|
|
|
const FILES = 'files'; |
17
|
|
|
const STREAM = 'stream'; |
18
|
|
|
|
19
|
|
|
const POLLING_INTERVAL_DEFAULT = 15; |
20
|
|
|
const POLLING_INTERVAL_MINIMUM = 10; |
21
|
|
|
|
22
|
8 |
|
public function file(string $file) |
23
|
|
|
{ |
24
|
8 |
|
$this->files = Arr::wrap($file); |
25
|
8 |
|
$this->method = static::FILES; |
26
|
|
|
|
27
|
8 |
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
3 |
|
public function files(array $files) |
31
|
|
|
{ |
32
|
3 |
|
$this->files = $files; |
33
|
3 |
|
$this->method = static::FILES; |
34
|
|
|
|
35
|
3 |
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
public function stream($stream, string $filename) |
39
|
|
|
{ |
40
|
2 |
|
$this->stream = $stream; |
41
|
2 |
|
$this->filename = $filename; |
42
|
2 |
|
$this->method = static::STREAM; |
43
|
|
|
|
44
|
2 |
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
8 |
|
public function checkStatus(bool $shouldCheck = true) |
48
|
|
|
{ |
49
|
8 |
|
$this->statusCheck = $shouldCheck; |
50
|
|
|
|
51
|
8 |
|
return $this; |
52
|
|
|
} |
53
|
|
|
|
54
|
9 |
|
public function shouldCheckStatus(): bool |
55
|
|
|
{ |
56
|
9 |
|
return $this->statusCheck; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Set a user who can be notified in case the fax fails to send. |
61
|
|
|
* @param mixed $notifiable [description] |
62
|
|
|
* @return InterfaxMessage |
63
|
|
|
*/ |
64
|
13 |
|
public function user($notifiable) |
65
|
|
|
{ |
66
|
13 |
|
$this->user = $notifiable; |
67
|
|
|
|
68
|
13 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
6 |
|
public function makeFiles(): array |
72
|
|
|
{ |
73
|
6 |
|
if ($this->method === static::STREAM) { |
74
|
|
|
return [ |
75
|
|
|
[ |
76
|
2 |
|
$this->stream, |
77
|
|
|
[ |
78
|
2 |
|
'name' => $this->filename, |
79
|
2 |
|
'mime_type' => app('filesystem')->mimeType(pathinfo($this->filename, PATHINFO_BASENAME)), |
80
|
|
|
], |
81
|
|
|
], |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
4 |
|
return $this->files; |
86
|
|
|
} |
87
|
|
|
|
88
|
2 |
|
public function sleep(): void |
89
|
|
|
{ |
90
|
2 |
|
$interval = config('services.interfax.interval', static::POLLING_INTERVAL_DEFAULT); |
91
|
2 |
|
sleep(max($interval, static::POLLING_INTERVAL_MINIMUM)); |
92
|
2 |
|
} |
93
|
|
|
} |
94
|
|
|
|