1 | <?php |
||
16 | class Message extends Attribute |
||
17 | { |
||
18 | const TYPE_TEXT = 'txt'; |
||
19 | const TYPE_IMG = 'img'; |
||
20 | const TYPE_VOICE = 'audio'; |
||
21 | const TYPE_VIDEO = 'video'; |
||
22 | const TYPE_CMD = 'cmd'; |
||
23 | /** |
||
24 | * Message type. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $type; |
||
29 | /** |
||
30 | * Target type, The message send target. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $target_type; |
||
35 | /** |
||
36 | * Message target user open id. |
||
37 | * |
||
38 | * @var string|array |
||
39 | */ |
||
40 | protected $to; |
||
41 | /** |
||
42 | * Message sender open id. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $from; |
||
47 | /** |
||
48 | * Extra attributes |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $ext; |
||
53 | |||
54 | /** |
||
55 | * Message attributes. |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $properties = []; |
||
60 | /** |
||
61 | * @var array |
||
62 | */ |
||
63 | protected $alias = [ |
||
64 | 'target' => 'to', |
||
65 | 'score' => 'target_type', |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * Constructor. |
||
70 | * |
||
71 | * @param array $attributes |
||
72 | */ |
||
73 | 10 | public function __construct(array $attributes = []) |
|
77 | |||
78 | /** |
||
79 | * Build the message object to array. |
||
80 | * |
||
81 | * @return array |
||
82 | */ |
||
83 | 3 | public function build() |
|
90 | |||
91 | /** |
||
92 | * Return type name message. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getType() |
||
100 | |||
101 | /** |
||
102 | * Magic getter. |
||
103 | * |
||
104 | * @param string $property |
||
105 | * |
||
106 | * @return mixed |
||
107 | */ |
||
108 | 11 | public function __get($property) |
|
116 | |||
117 | /** |
||
118 | * Magic setter. |
||
119 | * |
||
120 | * @param string $property |
||
121 | * @param mixed $value |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | 7 | public function __set($property, $value) |
|
135 | |||
136 | /** |
||
137 | * Validate the data. |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | 13 | protected function validateSelf() |
|
148 | |||
149 | /** |
||
150 | * Return the array data. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | 13 | public function toArray() |
|
164 | } |
||
165 |