Parses XML search results received from jobs.
Results are obtained by iterating over an instance of this class using a foreach loop. Each result can be a Splunk_ResultsFieldOrder, a Splunk_ResultsMessage, an associative array, or potentially instances of other classes in the future.
If the result is an associative array, it maps each field name to either a single value or an array of values.
$resultsReader = new Splunk_ResultsReader(...); foreach ($resultsReader as $result) { if ($result instanceof Splunk_ResultsFieldOrder) { // Process the field order print "FIELDS: " . implode(',', $result->getFieldNames()) . "\r\n"; } else if ($result instanceof Splunk_ResultsMessage) { // Process a message print "[{$result->getType()}] {$result->getText()}\r\n"; } else if (is_array($result)) { // Process a row print "{\r\n"; foreach ($result as $key => $valueOrValues) { if (is_array($valueOrValues)) { $values = $valueOrValues; $valuesString = implode(',', $values); print " {$key} => [{$valuesString}]\r\n"; } else { $value = $valueOrValues; print " {$key} => {$value}\r\n"; } } print "}\r\n"; } else { // Ignore unknown result type } }
package | Splunk |
---|
__construct(string | resource $streamOrXmlString)
string
resource
A string or stream containing results obtained from the {@link Splunk_Job::getResultsPage()} method.
current() : \Splunk_ResultsFieldOrder | \Splunk_ResultsMessage | array | mixed
next()
valid() : boolean
boolean
Whether there are any more elements.readMeta()
readNextElement()
readResult()
$atStart
$currentElement
$emptyXml
$xmlReader