1 | <?php |
||
42 | class MessageQueueProtocol |
||
43 | { |
||
44 | |||
45 | /** |
||
46 | * This is the line ending we use. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | const EOL = "\r\n"; |
||
51 | |||
52 | /** |
||
53 | * Protocol identifier. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | const PROTOCOL = 'MQ'; |
||
58 | |||
59 | /** |
||
60 | * Protocol version. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | const VERSION = '1.0'; |
||
65 | |||
66 | /** |
||
67 | * Default message type. |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | const MESSAGE_TYPE_MSG = 'MSG'; |
||
72 | |||
73 | /** |
||
74 | * Response code for a successfully accepted message. |
||
75 | * |
||
76 | * @var integer |
||
77 | */ |
||
78 | const STATUS_CODE_OK = 200; |
||
79 | |||
80 | /** |
||
81 | * Response code for a unknow message queue state. |
||
82 | * |
||
83 | * @var integer |
||
84 | */ |
||
85 | const STATUS_CODE_UNKNOWN = 100; |
||
86 | |||
87 | /** |
||
88 | * Response code if we can't accept a message. |
||
89 | * |
||
90 | * @var string |
||
91 | */ |
||
92 | const STATUS_CODE_INTERNAL_SERVER_ERROR = 500; |
||
93 | |||
94 | /** |
||
95 | * Array with the available response messages. |
||
96 | * |
||
97 | * @var array |
||
98 | */ |
||
99 | protected static $responseMessages = array( |
||
100 | MessageQueueProtocol::STATUS_CODE_OK => "OK", |
||
101 | MessageQueueProtocol::STATUS_CODE_UNKNOWN => "Unknown", |
||
102 | MessageQueueProtocol::STATUS_CODE_INTERNAL_SERVER_ERROR => "Internal Server Error" |
||
103 | ); |
||
104 | |||
105 | /** |
||
106 | * Prepares the header line for a remote method invocation request. |
||
107 | * |
||
108 | * @param string $string The packed remote method instance |
||
109 | * |
||
110 | * @return string The remote method invocation header for the passed remote method instance |
||
111 | */ |
||
112 | public static function prepareMessageHeader($string) |
||
116 | |||
117 | /** |
||
118 | * Prepares the result string that will be sent back to the client. |
||
119 | * |
||
120 | * @param integer $statusCode The status code we want to send back |
||
121 | * |
||
122 | * @return string The prepared result, read to send back |
||
123 | */ |
||
124 | public static function prepareResult($statusCode) |
||
138 | |||
139 | /** |
||
140 | * Prepares the header line for the passed remote method. |
||
141 | * |
||
142 | * @param string $method The remote method to prepare the head for |
||
143 | * @param string $string The packed remote method instance |
||
144 | * |
||
145 | * @return string The remote method header for the passed method |
||
146 | */ |
||
147 | protected static function prepareHeader($method, $string) |
||
157 | |||
158 | /** |
||
159 | * Returns an array with the available response messages. |
||
160 | * |
||
161 | * @return array The array with the available response messages |
||
162 | */ |
||
163 | public static function getResponseMessages() |
||
167 | |||
168 | /** |
||
169 | * Packs the passed instance. |
||
170 | * |
||
171 | * @param object $instance The instance to be packed |
||
172 | * |
||
173 | * @return string The packed instance |
||
174 | */ |
||
175 | public static function pack($instance) |
||
179 | |||
180 | /** |
||
181 | * Unpacks the passed instance. |
||
182 | * |
||
183 | * @param string $string The packed object instance. |
||
184 | * |
||
185 | * @return object The un-packed object instance |
||
186 | */ |
||
187 | public static function unpack($string) |
||
191 | } |
||
192 |