1 | <?php |
||
7 | class MessageBuilder |
||
8 | { |
||
9 | /** |
||
10 | * Message send targets |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $to; |
||
15 | |||
16 | /** |
||
17 | * Message send source user. |
||
18 | * |
||
19 | * This field can not empty, If not present this field, system default is admin. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $from; |
||
24 | |||
25 | /** |
||
26 | * Message object |
||
27 | * |
||
28 | * @var Message |
||
29 | */ |
||
30 | protected $msg; |
||
31 | |||
32 | /** |
||
33 | * target type, default is `users` |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $targetType = 'users'; |
||
38 | |||
39 | /** |
||
40 | * Extra attributes |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $ext; |
||
45 | |||
46 | /** |
||
47 | * Supported message send targets. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $targetTypes = [ |
||
52 | 'users', |
||
53 | 'chatgroups', |
||
54 | 'chatrooms', |
||
55 | ]; |
||
56 | |||
57 | /** |
||
58 | * MessageBuilder constructor. |
||
59 | * |
||
60 | * @param Message $msg |
||
61 | */ |
||
62 | 5 | public function __construct(Message $msg) |
|
72 | |||
73 | /** |
||
74 | * Set target users. |
||
75 | * |
||
76 | * @param array $target |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | 1 | public function to(array $target) |
|
85 | |||
86 | /** |
||
87 | * Set from user. |
||
88 | * |
||
89 | * @param string $from |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | 1 | public function from($from) |
|
98 | |||
99 | /** |
||
100 | * Set target_type |
||
101 | * |
||
102 | * @param string $type |
||
103 | * |
||
104 | * @return $this |
||
105 | * |
||
106 | * @throws InvalidArgumentException |
||
107 | */ |
||
108 | public function setTargetType($type) |
||
116 | |||
117 | 5 | public function build() |
|
131 | |||
132 | 4 | protected function validate(&$data) |
|
138 | } |
||
139 |