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\Exceptions\CouldNotSendNotification; |
10
|
|
|
|
11
|
|
|
class GammuChannel |
12
|
|
|
{ |
13
|
|
|
protected $config; |
14
|
|
|
|
15
|
|
|
protected $dbDriver; |
16
|
|
|
|
17
|
|
|
protected $apiDriver; |
18
|
|
|
|
19
|
|
|
private $method; |
20
|
|
|
|
21
|
2 |
|
public function __construct( |
22
|
|
|
Repository $config, DbDriver $dbDriver, ApiDriver $apiDriver |
23
|
|
|
) { |
24
|
2 |
|
$this->config = $config; |
25
|
2 |
|
$this->dbDriver = $dbDriver; |
26
|
2 |
|
$this->apiDriver = $apiDriver; |
27
|
2 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Send the given notification. |
31
|
|
|
* |
32
|
|
|
* @param mixed $notifiable |
33
|
|
|
* @param $notification |
34
|
|
|
*/ |
35
|
2 |
|
public function send($notifiable, Notification $notification) |
36
|
|
|
{ |
37
|
2 |
|
$payload = $notification->toGammu($notifiable); |
|
|
|
|
38
|
|
|
|
39
|
2 |
|
$destination = $payload->destination; |
40
|
2 |
|
$content = $payload->content; |
41
|
2 |
|
$sender = $payload->sender; |
42
|
2 |
|
$callback = $payload->callback; |
43
|
|
|
|
44
|
2 |
|
$this->getMethod(); |
45
|
|
|
|
46
|
2 |
|
switch ($this->method) { |
47
|
2 |
|
case 'db': |
48
|
1 |
|
$this->dbDriver->send($destination, $content, $sender); |
49
|
1 |
|
break; |
50
|
1 |
|
case 'api': |
51
|
1 |
|
$this->apiDriver->send($destination, $content, $sender, $callback); |
52
|
1 |
|
break; |
53
|
|
|
default: |
54
|
|
|
throw CouldNotSendNotification::invalidMethodProvided(); |
55
|
|
|
} |
56
|
2 |
|
} |
57
|
|
|
|
58
|
2 |
|
private function getMethod() |
59
|
|
|
{ |
60
|
2 |
|
$this->method = $this->config->get('services.gammu.method'); |
61
|
|
|
|
62
|
2 |
|
if (empty($this->method)) { |
63
|
|
|
throw CouldNotSendNotification::methodNotProvided(); |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.