]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - extlib/Stomp/Frame.php
Several fixes to make RabbitMQ a player.
[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
21 /**
22  * Stomp Frames are messages that are sent and received on a StompConnection.
23  *
24  * @package Stomp
25  * @author Hiram Chirino <hiram@hiramchirino.com>
26  * @author Dejan Bosanac <dejan@nighttale.net>
27  * @author Michael Caplan <mcaplan@labnet.net>
28  * @version $Revision: 36 $
29  */
30 class Stomp_Frame
31 {
32     public $command;
33     public $headers = array();
34     public $body;
35     
36     /**
37      * Constructor
38      *
39      * @param string $command
40      * @param array $headers
41      * @param string $body
42      */
43     public function __construct ($command = null, $headers = null, $body = null)
44     {
45         $this->_init($command, $headers, $body);
46     }
47     
48     protected function _init ($command = null, $headers = null, $body = null)
49     {
50         $this->command = $command;
51         if ($headers != null) {
52             $this->headers = $headers;
53         }
54         $this->body = $body;
55         
56         if ($this->command == 'ERROR') {
57             require_once 'Stomp/Exception.php';
58             throw new Stomp_Exception($this->headers['message'], 0, $this->body);
59         }
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         $data .= "\x00\n"; // Should there really be a linefeed here?
78         return $data;
79     }
80 }
81 ?>