]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/Stomp/Frame.php
Bump to version 1.0.0
[quix0rs-gnu-social.git] / extlib / Stomp / Frame.php
1 <?php\r
2 /**\r
3  *\r
4  * Copyright 2005-2006 The Apache Software Foundation\r
5  *\r
6  * Licensed under the Apache License, Version 2.0 (the "License");\r
7  * you may not use this file except in compliance with the License.\r
8  * You may obtain a copy of the License at\r
9  *\r
10  * http://www.apache.org/licenses/LICENSE-2.0\r
11  *\r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  */\r
18 \r
19 /* vim: set expandtab tabstop=3 shiftwidth=3: */\r
20 \r
21 /**\r
22  * Stomp Frames are messages that are sent and received on a stomp connection.\r
23  *\r
24  * @package Stomp\r
25  */\r
26 class StompFrame\r
27 {\r
28     public $command;\r
29     public $headers = array();\r
30     public $body;\r
31     \r
32     /**\r
33      * Constructor\r
34      *\r
35      * @param string $command\r
36      * @param array $headers\r
37      * @param string $body\r
38      */\r
39     public function __construct ($command = null, $headers = null, $body = null)\r
40     {\r
41         $this->_init($command, $headers, $body);\r
42     }\r
43     \r
44     protected function _init ($command = null, $headers = null, $body = null)\r
45     {\r
46         $this->command = $command;\r
47         if ($headers != null) {\r
48             $this->headers = $headers;\r
49         }\r
50         $this->body = $body;\r
51         \r
52         if ($this->command == 'ERROR') {\r
53             require_once 'Exception.php';\r
54             throw new StompException($this->headers['message'], 0, $this->body);\r
55         }\r
56     }\r
57     \r
58     /**\r
59      * Convert frame to transportable string\r
60      *\r
61      * @return string\r
62      */\r
63     public function __toString()\r
64     {\r
65         $data = $this->command . "\n";\r
66         \r
67         foreach ($this->headers as $name => $value) {\r
68             $data .= $name . ": " . $value . "\n";\r
69         }\r
70         \r
71         $data .= "\n";\r
72         $data .= $this->body;\r
73         return $data .= "\x00";\r
74     }\r
75 }\r
76 ?>