9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
15 * @package Phergie_Plugin_Http
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie_Plugin_Http
23 * Data structure for HTTP response information.
26 * @package Phergie_Plugin_Http
27 * @author Phergie Development Team <team@phergie.org>
28 * @license http://phergie.org/license New BSD License
29 * @link http://pear.phergie.org/package/Phergie_Plugin_Http
31 class Phergie_Plugin_Http_Response
34 * HTTP response code or 0 if no HTTP response was received
41 * Description of the HTTP response code or the error message if no HTTP
42 * response was received
49 * Content of the response body, decoded for supported content types
56 * Associative array mapping response header names to their values
63 * Associative array containing other metadata about the response
70 * Sets the HTTP response code.
72 * @param string $code Response code
74 * @return Phergie_Plugin_Http_Response Provides a fluent interface
76 public function setCode($code)
83 * Returns the HTTP response code.
85 * @return string Response code
87 public function getCode()
93 * Returns whether the response indicates a client- or server-side error.
95 * @return bool TRUE if the response indicates an error, FALSE otherwise
97 public function isError()
99 switch (substr($this->code, 0, 1)) {
110 * Sets the HTTP response description.
112 * @param string $message Response description
114 * @return Phergie_Plugin_Http_Response Provides a fluent interface
116 public function setMessage($message)
118 $this->message = $message;
123 * Returns the HTTP response description.
127 public function getMessage()
129 return $this->message;
133 * Sets the content of the response body.
135 * @param mixed $content Response body content
137 * @return Phergie_Plugin_Http_Response Provides a fluent interface
139 public function setContent($content)
141 $this->content = $content;
146 * Returns the content of the response body.
148 * @return mixed Response body content, decoded for supported content
151 public function getContent()
153 return $this->content;
157 * Sets the response headers.
159 * @param array $headers Associative array of response headers indexed
162 * @return Phergie_Plugin_Http_Response Provides a fluent interface
164 public function setHeaders(array $headers)
166 $names = array_map('strtolower', array_keys($headers));
167 $values = array_values($headers);
168 $this->headers = array_combine($names, $values);
173 * Returns all response headers or the value of a single specified
176 * @param string $name Optional name of a single header for which the
177 * associated value should be returned
179 * @return array|string Associative array of all header values, a string
180 * containing the value of the header indicated by $name if one
181 * is set, or null if one is not
183 public function getHeaders($name = null)
186 $name = strtolower($name);
187 if (empty($this->headers[$name])) {
190 return $this->headers[$name];
192 return $this->headers;
196 * Sets the response metadata.
198 * @param array $meta Associative array of response metadata
200 * @return Phergie_Plugin_Http_Response Provides a fluent interface
202 public function setMeta(array $meta)
209 * Returns all metadata or the value of a single specified metadatum.
211 * @param string $name Optional name of a single metadatum for which the
212 * associated value should be returned
214 * @return array|string|null Associative array of all metadata values, a
215 * string containing the value of the metadatum indicated by
216 * $name if one is set, or null if one is not
218 public function getMeta($name = null)
221 if (empty($this->meta[$name])) {
224 return $this->meta[$name];