'0')). * @property-read string $body Content of the response, * as a single byte string. * @property-read resource $bodyStream * Content of the response, as a stream * (of the type returned by fopen()). */ class Splunk_HttpResponse { private $state; private $body; // lazy private $bodyStream; // lazy /* @internal */ public function __construct($state) { $this->state = $state; $this->body = NULL; $this->bodyStream = NULL; } // === Accessors === /** @internal */ public function __get($key) { if ($key === 'body') return $this->getBody(); else if ($key === 'bodyStream') return $this->getBodyStream(); else return $this->state[$key]; } private function getBody() { if (array_key_exists('body', $this->state)) return $this->state['body']; if ($this->body === NULL) { if (!array_key_exists('bodyStream', $this->state)) throw new Splunk_UnsupportedOperationException( 'Response object does not contain body stream.'); $this->body = Splunk_Util::stream_get_contents( $this->state['bodyStream']); } return $this->body; } private function getBodyStream() { if (array_key_exists('bodyStream', $this->state)) return $this->state['bodyStream']; if ($this->bodyStream === NULL) { if (!array_key_exists('body', $this->state)) throw new Splunk_UnsupportedOperationException( 'Response object does not contain body.'); $this->bodyStream = Splunk_StringStream::create($this->state['body']); } return $this->bodyStream; } }