1 | <?php |
||
10 | class FacebookPosterChannel |
||
11 | { |
||
12 | /** @var \Facebook\Facebook */ |
||
13 | protected $facebook; |
||
14 | |||
15 | /** |
||
16 | * @param \Facebook\Facebook $facebook |
||
17 | */ |
||
18 | public function __construct(Facebook $facebook) |
||
19 | { |
||
20 | $this->facebook = $facebook; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Send the given notification. |
||
25 | * |
||
26 | * @param mixed $notifiable |
||
27 | * @param \Illuminate\Notifications\Notification $notification |
||
28 | * |
||
29 | * @throws InvalidPostContentException |
||
30 | */ |
||
31 | public function send($notifiable, Notification $notification) |
||
32 | { |
||
33 | if ($facebookSettings = $notifiable->routeNotificationFor('facebookPoster')) { |
||
34 | $this->switchSettings($facebookSettings); |
||
35 | } |
||
36 | |||
37 | $facebookMessage = $notification->toFacebookPoster($notifiable); |
||
|
|||
38 | |||
39 | $postBody = $facebookMessage->getPostBody(); |
||
40 | |||
41 | $endpoint = $facebookMessage->getApiEndpoint(); |
||
42 | |||
43 | $this->guardAgainstInvalidPostContent($postBody); |
||
44 | |||
45 | // here we check if post body has image or video to upload it first to facebook |
||
46 | if (isset($postBody['media'])) { |
||
47 | $endpoint = $postBody['media']->getApiEndpoint(); |
||
48 | |||
49 | if ($postBody['media'] instanceof Video) { |
||
50 | $postBody = array_merge($postBody, $postBody['media']->getData()); |
||
51 | } |
||
52 | |||
53 | $method = $postBody['media']->getMethod(); |
||
54 | |||
55 | $postBody['source'] = $this->facebook->{$method}($postBody['media']->getPath()); |
||
56 | |||
57 | unset($postBody['media']); |
||
58 | } |
||
59 | |||
60 | $this->facebook->post($endpoint, $postBody); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param array $postBody |
||
65 | * |
||
66 | * @throws \NotificationChannels\FacebookPoster\Exceptions\InvalidPostContent |
||
67 | */ |
||
68 | protected function guardAgainstInvalidPostContent($postBody) |
||
69 | { |
||
70 | if (! is_null($postBody['message'])) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | if (isset($postBody['link'])) { |
||
75 | return; |
||
76 | } |
||
77 | |||
78 | if (isset($postBody['media'])) { |
||
79 | return; |
||
80 | } |
||
81 | |||
82 | throw InvalidPostContent::noContentSet(); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Use per user settings instead of default ones. |
||
87 | * @param $facebookSettings |
||
88 | */ |
||
89 | private function switchSettings($facebookSettings) |
||
93 | } |
||
94 |
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.