* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Result */ /** * Query result * * This base class provides access to the response and decoded data. If you need more functionality * like resultset parsing use one of the subclasses * * @package Solarium * @subpackage Result */ class Solarium_Result { /** * Response object * * @var Solarium_Client_Response */ protected $_response; /** * Decode response data * * This is lazy loaded, {@link getData()} * * @var array */ protected $_data; /** * Query used for this request * * @var Solarium_Query */ protected $_query; /** * Solarium client instance * * @var Solarium_Client */ protected $_client; /** * Constructor * * @param Solarium_Client $client * @param Solarium_Query $query * @param Solarium_Client_Response $response * @return void */ public function __construct($client, $query, $response) { $this->_client = $client; $this->_query = $query; $this->_response = $response; // check status for error (range of 400 and 500) $statusNum = floor($response->getStatusCode() / 100); if ($statusNum == 4 || $statusNum == 5) { throw new Solarium_Client_HttpException( $response->getStatusMessage(), $response->getStatusCode() ); } } /** * Get response object * * This is the raw HTTP response object, not the parsed data! * * @return Solarium_Client_Response */ public function getResponse() { return $this->_response; } /** * Get query instance * * @return Solarium_Query */ public function getQuery() { return $this->_query; } /** * Get Solr response data * * Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse. * * @return array */ public function getData() { if (null == $this->_data) { $this->_data = json_decode($this->_response->getBody(), true); if (null === $this->_data) { throw new Solarium_Exception( 'Solr JSON response could not be decoded' ); } } return $this->_data; } }