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