1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Gammu; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notification; |
6
|
|
|
use Illuminate\Contracts\Config\Repository; |
7
|
|
|
use NotificationChannels\Gammu\Drivers\DbDriver; |
8
|
|
|
use NotificationChannels\Gammu\Drivers\ApiDriver; |
9
|
|
|
use NotificationChannels\Gammu\Drivers\RedisDriver; |
10
|
|
|
use NotificationChannels\Gammu\Exceptions\CouldNotSendNotification; |
11
|
|
|
|
12
|
|
|
class GammuChannel |
13
|
|
|
{ |
14
|
|
|
protected $config; |
15
|
|
|
|
16
|
|
|
protected $dbDriver; |
17
|
|
|
|
18
|
|
|
protected $apiDriver; |
19
|
|
|
|
20
|
|
|
protected $redisDriver; |
21
|
|
|
|
22
|
|
|
private $method; |
23
|
|
|
|
24
|
|
|
public function __construct( |
25
|
|
|
Repository $config, DbDriver $dbDriver, ApiDriver $apiDriver, RedisDriver $redisDriver |
26
|
|
|
) { |
27
|
|
|
$this->config = $config; |
28
|
|
|
$this->dbDriver = $dbDriver; |
29
|
|
|
$this->apiDriver = $apiDriver; |
30
|
|
|
$this->redisDriver = $redisDriver; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Send the given notification. |
35
|
|
|
* |
36
|
|
|
* @param mixed $notifiable |
37
|
|
|
* @param $notification |
38
|
|
|
*/ |
39
|
|
|
public function send($notifiable, Notification $notification) |
40
|
|
|
{ |
41
|
|
|
$payload = $notification->toGammu($notifiable); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$destination = $payload->destination; |
44
|
|
|
$content = $payload->content; |
45
|
|
|
$sender = $payload->sender; |
46
|
|
|
$callback = $payload->callback; |
47
|
|
|
$channel = $payload->channel; |
48
|
|
|
|
49
|
|
|
$this->getMethod(); |
50
|
|
|
|
51
|
|
|
switch ($this->method) { |
52
|
|
|
case 'db': |
53
|
|
|
$this->dbDriver->send($destination, $content, $sender); |
54
|
|
|
break; |
55
|
|
|
case 'api': |
56
|
|
|
$this->apiDriver->send($destination, $content, $sender, $callback); |
57
|
|
|
break; |
58
|
|
|
case 'redis': |
59
|
|
|
$this->redisDriver->send($destination, $content, $channel, $sender, $callback); |
60
|
|
|
break; |
61
|
|
|
default: |
62
|
|
|
throw CouldNotSendNotification::invalidMethodProvided(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
private function getMethod() |
67
|
|
|
{ |
68
|
|
|
$this->method = $this->config->get('services.gammu.method'); |
69
|
|
|
|
70
|
|
|
if (empty($this->method)) { |
71
|
|
|
throw CouldNotSendNotification::methodNotProvided(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.