1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\FacebookPoster; |
4
|
|
|
|
5
|
|
|
use Facebook\Facebook; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent; |
8
|
|
|
|
9
|
|
|
class FacebookPosterChannel |
10
|
|
|
{ |
11
|
|
|
/** @var \Facebook\Facebook */ |
12
|
|
|
protected $facebook; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param \Facebook\Facebook $facebook |
16
|
|
|
*/ |
17
|
4 |
|
public function __construct(Facebook $facebook) |
18
|
|
|
{ |
19
|
4 |
|
$this->facebook = $facebook; |
20
|
4 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Send the given notification. |
24
|
|
|
* |
25
|
|
|
* @param mixed $notifiable |
26
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
27
|
|
|
* |
28
|
|
|
* @throws InvalidPostContentException |
29
|
|
|
*/ |
30
|
4 |
|
public function send($notifiable, Notification $notification) |
31
|
|
|
{ |
32
|
4 |
|
if ($facebookSettings = $notifiable->routeNotificationFor('facebookPoster')) { |
33
|
|
|
$this->switchSettings($facebookSettings); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
$facebookMessage = $notification->toFacebookPoster($notifiable); |
|
|
|
|
37
|
|
|
|
38
|
4 |
|
$postBody = $facebookMessage->getPostBody(); |
39
|
|
|
|
40
|
4 |
|
$endpoint = $facebookMessage->getApiEndpoint(); |
41
|
|
|
|
42
|
4 |
|
if (isset($postBody['media'])) { |
43
|
2 |
|
$endpoint = $postBody['media']->getApiEndpoint(); |
44
|
|
|
|
45
|
2 |
|
$postBody = array_merge($postBody, $postBody['media']->getData()); |
46
|
|
|
|
47
|
2 |
|
$method = $postBody['media']->getApiMethod(); |
48
|
|
|
|
49
|
2 |
|
$postBody['source'] = $this->facebook->{$method}($postBody['media']->getPath()); |
50
|
|
|
|
51
|
2 |
|
unset($postBody['media']); |
52
|
|
|
} |
53
|
|
|
|
54
|
4 |
|
$this->facebook->post($endpoint, $postBody); |
55
|
4 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Use per user settings instead of default ones. |
59
|
|
|
* @param $facebookSettings |
60
|
|
|
*/ |
61
|
|
|
private function switchSettings($facebookSettings) |
62
|
|
|
{ |
63
|
|
|
$this->facebook = new Facebook($facebookSettings); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
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.