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