1 | <?php |
||
46 | class Message implements ProtocolImplementationInterface |
||
47 | { |
||
48 | /** |
||
49 | * Chat between to users. |
||
50 | */ |
||
51 | |||
52 | const TYPE_CHAT = 'chat'; |
||
53 | |||
54 | /** |
||
55 | * Chat in a multi-user channel (MUC). |
||
56 | */ |
||
57 | const TYPE_GROUPCHAT = 'groupchat'; |
||
58 | |||
59 | /** |
||
60 | * Message type. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $type = self::TYPE_CHAT; |
||
65 | |||
66 | /** |
||
67 | * Set message receiver. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $to; |
||
72 | |||
73 | /** |
||
74 | * Message. |
||
75 | * |
||
76 | * @var string |
||
77 | */ |
||
78 | protected $message = ''; |
||
79 | |||
80 | /** |
||
81 | * Constructor. |
||
82 | * |
||
83 | * @param string $message |
||
84 | * @param string $to |
||
85 | * @param string $type |
||
86 | */ |
||
87 | 3 | public function __construct($message = '', $to = '', $type = self::TYPE_CHAT) |
|
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | */ |
||
95 | 3 | public function toString() |
|
96 | { |
||
97 | 3 | return XML::quoteMessage( |
|
98 | 3 | '<message type="%s" id="%s" to="%s"><body>%s</body></message>', |
|
99 | 3 | $this->getType(), |
|
100 | 3 | XML::generateId(), |
|
101 | 3 | $this->getTo(), |
|
102 | 3 | $this->getMessage() |
|
103 | 3 | ); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Get message type. |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 3 | public function getType() |
|
112 | { |
||
113 | 3 | return $this->type; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * Set message type. |
||
118 | * |
||
119 | * See {@link self::TYPE_CHAT} and {@link self::TYPE_GROUPCHAT} |
||
120 | * |
||
121 | * @param string $type |
||
122 | * @return $this |
||
123 | */ |
||
124 | 3 | public function setType($type) |
|
125 | { |
||
126 | 3 | $this->type = $type; |
|
127 | 3 | return $this; |
|
128 | } |
||
129 | |||
130 | /** |
||
131 | * Get message receiver. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | 3 | public function getTo() |
|
136 | { |
||
137 | 3 | return $this->to; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Set message receiver. |
||
142 | * |
||
143 | * @param string $to |
||
144 | * @return $this |
||
145 | */ |
||
146 | 3 | public function setTo($to) |
|
151 | |||
152 | /** |
||
153 | * Get message. |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | 3 | public function getMessage() |
|
161 | |||
162 | /** |
||
163 | * Set message. |
||
164 | * |
||
165 | * @param string $message |
||
166 | * @return $this |
||
167 | */ |
||
168 | 3 | public function setMessage($message) |
|
173 | } |
||
174 |