1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Kavenegar; |
4
|
|
|
|
5
|
|
|
class KavenegarMessage |
6
|
|
|
{ |
7
|
|
|
/** @var string */ |
8
|
|
|
protected $receptor; |
9
|
|
|
|
10
|
|
|
/** @var string */ |
11
|
|
|
protected $sender; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
protected $message; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $template; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $type; |
21
|
|
|
|
22
|
|
|
/** @var array */ |
23
|
|
|
protected $tokens = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param string $receptor |
27
|
|
|
* @return static |
28
|
|
|
*/ |
29
|
|
|
public static function create($receptor = '') |
30
|
|
|
{ |
31
|
|
|
return new static($receptor); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $receptor |
36
|
|
|
*/ |
37
|
|
|
public function __construct($receptor = '') |
38
|
|
|
{ |
39
|
|
|
$this->receptor = $receptor; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Set the receptor. |
44
|
|
|
* |
45
|
|
|
* @param $receptor |
46
|
|
|
* |
47
|
|
|
* @return $this |
48
|
|
|
*/ |
49
|
|
|
public function receptor($receptor) |
50
|
|
|
{ |
51
|
|
|
$this->receptor = $receptor; |
52
|
|
|
|
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Set the sender. |
58
|
|
|
* |
59
|
|
|
* @param $sender |
60
|
|
|
* |
61
|
|
|
* @return $this |
62
|
|
|
*/ |
63
|
|
|
public function sender($sender) |
64
|
|
|
{ |
65
|
|
|
$this->sender = $sender; |
66
|
|
|
|
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Set the message. |
72
|
|
|
* |
73
|
|
|
* @param $message |
74
|
|
|
* |
75
|
|
|
* @return $this |
76
|
|
|
*/ |
77
|
|
|
public function message($message) |
78
|
|
|
{ |
79
|
|
|
$this->message = $message; |
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Set the template. |
86
|
|
|
* |
87
|
|
|
* @param $template |
88
|
|
|
* |
89
|
|
|
* @return $this |
90
|
|
|
*/ |
91
|
|
|
public function template($template) |
92
|
|
|
{ |
93
|
|
|
$this->template = $template; |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set the type. |
100
|
|
|
* |
101
|
|
|
* @param $type |
102
|
|
|
* |
103
|
|
|
* @return $this |
104
|
|
|
*/ |
105
|
|
|
public function type($type) |
106
|
|
|
{ |
107
|
|
|
$this->type = $type; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set the token. |
114
|
|
|
* |
115
|
|
|
* @param string $token |
116
|
|
|
* @param string $num |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
|
|
public function token($token, $num = '') |
120
|
|
|
{ |
121
|
|
|
$this->tokens = array_merge($this->tokens, ["token$num" => $token]); |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
|
|
public function toArray() |
130
|
|
|
{ |
131
|
|
|
$parameters = []; |
132
|
|
|
if ($this->receptor) |
133
|
|
|
$parameters = array_merge($parameters, ['receptor' => $this->receptor]); |
134
|
|
|
|
135
|
|
|
if ($this->sender) |
136
|
|
|
$parameters = array_merge($parameters, ['sender' => $this->sender]); |
137
|
|
|
|
138
|
|
|
if ($this->message) |
139
|
|
|
$parameters = array_merge($parameters, ['message' => $this->message]); |
140
|
|
|
|
141
|
|
|
if ($this->type) |
142
|
|
|
$parameters = array_merge($parameters, ['type' => $this->type]); |
143
|
|
|
|
144
|
|
|
if ($this->template) |
145
|
|
|
$parameters = array_merge($parameters, ['template' => $this->template]); |
146
|
|
|
|
147
|
|
|
if (count($this->tokens)) |
148
|
|
|
$parameters = array_merge($parameters, $this->tokens); |
149
|
|
|
|
150
|
|
|
return $parameters; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|