1 | <?php |
||
25 | class Message extends Attribute |
||
26 | { |
||
27 | const TYPE_TEXT = 'txt'; |
||
28 | const TYPE_IMG = 'img'; |
||
29 | const TYPE_VOICE = 'audio'; |
||
30 | const TYPE_VIDEO = 'video'; |
||
31 | const TYPE_CMD = 'cmd'; |
||
32 | /** |
||
33 | * Message type. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $type; |
||
38 | /** |
||
39 | * Target type, The message send target. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $target_type; |
||
44 | /** |
||
45 | * Message target user open id. |
||
46 | * |
||
47 | * @var string|array |
||
48 | */ |
||
49 | protected $to; |
||
50 | /** |
||
51 | * Message sender open id. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $from; |
||
56 | /** |
||
57 | * Extra attributes. |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $ext; |
||
62 | |||
63 | /** |
||
64 | * Message attributes. |
||
65 | * |
||
66 | * @var array |
||
67 | */ |
||
68 | protected $properties = []; |
||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $alias = [ |
||
73 | 'target' => 'to', |
||
74 | 'score' => 'target_type', |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Constructor. |
||
79 | * |
||
80 | * @param array $attributes |
||
81 | */ |
||
82 | 10 | public function __construct(array $attributes = []) |
|
86 | |||
87 | /** |
||
88 | * Build the message object to array. |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | 3 | public function build() |
|
99 | |||
100 | /** |
||
101 | * Return type name message. |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getType() |
||
109 | |||
110 | /** |
||
111 | * Magic getter. |
||
112 | * |
||
113 | * @param string $property |
||
114 | * |
||
115 | * @return mixed |
||
116 | */ |
||
117 | 11 | public function __get($property) |
|
125 | |||
126 | /** |
||
127 | * Magic setter. |
||
128 | * |
||
129 | * @param string $property |
||
130 | * @param mixed $value |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | 7 | public function __set($property, $value) |
|
144 | |||
145 | /** |
||
146 | * Validate the data. |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | 13 | protected function validateSelf() |
|
158 | |||
159 | /** |
||
160 | * Return the array data. |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | 13 | public function toArray() |
|
174 | } |
||
175 |