* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Client */ /** * Class for describing a response * * @package Solarium * @subpackage Client */ class Solarium_Client_Response { /** * Headers * * @var array */ protected $_headers; /** * Body * * @var string */ protected $_body; /** * HTTP response code * * @var int */ protected $_statusCode; /** * HTTP response message * * @var string */ protected $_statusMessage; /** * Constructor * * @param string $body * @param array $headers */ public function __construct($body, $headers = array()) { $this->_body = $body; $this->_headers = $headers; $this->_setHeaders($headers); } /** * Get body data * * @return string */ public function getBody() { return $this->_body; } /** * Get response headers * * @return array */ public function getHeaders() { return $this->_headers; } /** * Get status code * * @return int */ public function getStatusCode() { return $this->_statusCode; } /** * Get status message * * @return string */ public function getStatusMessage() { return $this->_statusMessage; } /** * Set headers * * @param array $headers * @return void */ public function _setHeaders($headers) { $this->_headers = $headers; // get the status header $statusHeader = null; foreach ($headers AS $header) { if (substr($header, 0, 4) == 'HTTP') { $statusHeader = $header; break; } } if (null == $statusHeader) { throw new Solarium_Client_HttpException("No HTTP status found"); } // parse header like "$statusInfo[1]" into code and message // $statusInfo[1] = the HTTP response code // $statusInfo[2] = the response message $statusInfo = explode(' ', $statusHeader, 3); $this->_statusCode = $statusInfo[1]; $this->_statusMessage = $statusInfo[2]; } }