1
|
|
|
<?php |
2
|
|
|
namespace NotificationChannels\OneSignal; |
3
|
|
|
|
4
|
|
|
use Illuminate\Notifications\Notification; |
5
|
|
|
|
6
|
|
|
class OneSignalPayloadFactory |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Make a one signal notification payload. |
10
|
|
|
* |
11
|
|
|
* @param mixed $notifiable |
12
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
13
|
|
|
* @param mixed $targeting |
14
|
|
|
* |
15
|
|
|
* @return array |
16
|
|
|
*/ |
17
|
3 |
|
public static function make($notifiable, Notification $notification, $targeting): array |
18
|
|
|
{ |
19
|
3 |
|
$payload = $notification->toOneSignal($notifiable)->toArray(); |
|
|
|
|
20
|
|
|
|
21
|
3 |
|
if (static::isTargetingEmail($targeting)) { |
22
|
1 |
|
$payload['filters'] = collect([['field' => 'email', 'value' => $targeting['email']]]); |
23
|
2 |
|
} elseif (static::isTargetingTags($targeting)) { |
24
|
1 |
|
$payload['tags'] = collect([$targeting['tags']]); |
25
|
1 |
|
} elseif (static::isTargetingIncludedSegments($targeting)) { |
26
|
|
|
$payload['included_segments'] = collect($targeting['included_segments']); |
27
|
|
|
} elseif (static::isTargetingExcludedSegments($targeting)) { |
|
|
|
|
28
|
|
|
$payload['excluded_segments'] = collect($targeting['excluded_segments']); |
29
|
|
|
} else { |
30
|
|
|
$payload['include_player_ids'] = collect($targeting); |
31
|
|
|
} |
32
|
|
|
//dd($payload); |
33
|
|
|
|
34
|
2 |
|
return $payload; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param mixed $targeting |
39
|
|
|
* |
40
|
|
|
* @return bool |
41
|
|
|
*/ |
42
|
3 |
|
protected static function isTargetingEmail($targeting) |
43
|
|
|
{ |
44
|
3 |
|
return is_array($targeting) && array_key_exists('email', $targeting); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param mixed $targeting |
49
|
|
|
* |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
2 |
|
protected static function isTargetingTags($targeting) |
53
|
|
|
{ |
54
|
2 |
|
return is_array($targeting) && array_key_exists('tags', $targeting); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param mixed $targeting |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
1 |
|
protected static function isTargetingIncludedSegments($targeting) |
63
|
|
|
{ |
64
|
1 |
|
return is_array($targeting) && array_key_exists('included_segments', $targeting); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param mixed $targeting |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
protected static function isTargetingExludedSegments($targeting) |
73
|
|
|
{ |
74
|
|
|
return is_array($targeting) && array_key_exists('excluded_segments', $targeting); |
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.