1 | <?php |
||
16 | class MessageBuilder |
||
17 | { |
||
18 | /** |
||
19 | * Message send targets. |
||
20 | * |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $to; |
||
24 | |||
25 | /** |
||
26 | * Message send source user. |
||
27 | * |
||
28 | * This field can not empty, If not present this field, system default is admin. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $from; |
||
33 | |||
34 | /** |
||
35 | * Message object. |
||
36 | * |
||
37 | * @var Message |
||
38 | */ |
||
39 | protected $msg; |
||
40 | |||
41 | /** |
||
42 | * target type, default is `users`. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $targetType = 'users'; |
||
47 | |||
48 | /** |
||
49 | * Extra attributes. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $ext; |
||
54 | |||
55 | /** |
||
56 | * Supported message send targets. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | protected $targetTypes = [ |
||
61 | 'users', |
||
62 | 'chatgroups', |
||
63 | 'chatrooms', |
||
64 | ]; |
||
65 | |||
66 | /** |
||
67 | * MessageBuilder constructor. |
||
68 | * |
||
69 | * @param Message $msg |
||
70 | */ |
||
71 | 5 | public function __construct(Message $msg) |
|
81 | |||
82 | /** |
||
83 | * Set target users. |
||
84 | * |
||
85 | * @param array $target |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | 1 | public function to(array $target) |
|
95 | |||
96 | /** |
||
97 | * Set from user. |
||
98 | * |
||
99 | * @param string $from |
||
100 | * |
||
101 | * @return $this |
||
102 | */ |
||
103 | 1 | public function from($from) |
|
109 | |||
110 | /** |
||
111 | * Set target_type. |
||
112 | * |
||
113 | * @param string $type |
||
114 | * |
||
115 | * @throws InvalidArgumentException |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | public function setTargetType($type) |
||
128 | |||
129 | 5 | public function build() |
|
143 | |||
144 | 4 | protected function validate(&$data) |
|
150 | } |
||
151 |