/** * Constructs a new search results string or stream. * * @param string|resource $streamOrXmlString * A string or stream containing results obtained from the * {@link Splunk_Job::getResultsPage()} method. */ public function __construct($streamOrXmlString) { if (is_string($streamOrXmlString)) { $string = $streamOrXmlString; $stream = Splunk_StringStream::create($string); } else { $stream = $streamOrXmlString; } // Search jobs lacking results return a blank document (with HTTP 200). if (feof($stream)) { $this->emptyXml = TRUE; $this->currentElement = NULL; $this->atStart = TRUE; return; } else { $this->emptyXml = FALSE; } $streamUri = Splunk_StreamStream::createUriForStream($stream); $this->xmlReader = new XMLReader(); $this->xmlReader->open($streamUri); $this->currentElement = $this->readNextElement(); $this->atStart = TRUE; }
/** * Returns a single page of results from this job, * which may or may not be done running. * * @param array $args (optional) {<br/> * **count**: (optional) The maximum number of results to return, * or -1 to return as many as possible. * Defaults to returning as many as possible.<br/> * **offset**: (optional) The offset of the first result to return. * Defaults to 0.<br/> * * **field_list**: (optional) Comma-separated list of fields to return * in the result set. Defaults to all fields.<br/> * **output_mode**: (optional) The output format of the result. Valid * values:<br/> * - "csv"<br/> * - "raw"<br/> * - "xml": The format parsed by Splunk_ResultsReader. * <br/> * - "json"<br/> * Defaults to "xml".<br/> * You should not change this unless you are parsing * results yourself.<br/> * **search**: (optional) The post processing search to apply to * results. Can be any valid search language string. * For example "search sourcetype=splunkd" will match any * result whose "sourcetype" field is "splunkd".<br/> * } * @return resource The results (i.e. transformed events) * of this job, as a stream. * @throws Splunk_IOException * @link http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#search.2Fjobs.2F.7Bsearch_id.7D.2Fresults_preview */ public function getResultsPreviewPage($args = array()) { $response = $this->fetchPage('results_preview', $args); if ($response->status == 204) { // The REST API throws a 204 when a preview is being generated // and no results are available. This isn't a friendly behavior // for clients. return Splunk_StringStream::create(''); } return $response->bodyStream; }
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; }