Commit fcb9bf90 authored by Bas de Nooijer's avatar Bas de Nooijer

Implemented debug component result classes and result parser

parent bbdb8cc5
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Client
*/
/**
* Parse select component Debug result from the data
*
* @package Solarium
* @subpackage Client
*/
class Solarium_Client_ResponseParser_Select_Component_Debug
{
/**
* Parse result data into result objects
*
* @param Solarium_Query_Select $query
* @param Solarium_Query_Select_Component_Debug $component
* @param array $data
* @return Solarium_Result_Select_Debug|null
*/
public function parse($query, $component, $data)
{
$result = null;
if (isset($data['debug'])) {
$debug = $data['debug'];
// get basic values from data
$queryString = (isset($debug['querystring'])) ? $debug['querystring'] : '';
$parsedQuery = (isset($debug['parsedquery'])) ? $debug['parsedquery'] : '';
$queryParser = (isset($debug['QParser'])) ? $debug['QParser'] : '';
$otherQuery = (isset($debug['otherQuery'])) ? $debug['otherQuery'] : '';
// parse explain data
if (isset($debug['explain']) && is_array($debug['explain'])) {
$explain = $this->_parseDocumentSet($debug['explain']);
} else {
$explain = new Solarium_Result_Select_Debug_DocumentSet(array());
}
// parse explainOther data
if (isset($debug['explainOther']) && is_array($debug['explainOther'])) {
$explainOther = $this->_parseDocumentSet($debug['explainOther']);
} else {
$explainOther = new Solarium_Result_Select_Debug_DocumentSet(array());
}
// parse timing data
$timing = null;
if (isset($debug['timing']) && is_array($debug['timing'])) {
$time = null;
$timingPhases = array();
foreach ($debug['timing'] as $key => $timingData) {
switch($key) {
case 'time':
$time = $timingData;
break;
default:
$timingPhases[$key] = $this->_parseTimingPhase($key, $timingData);
}
}
$timing = new Solarium_Result_Select_Debug_Timing($time, $timingPhases);
}
// create result object
$result = new Solarium_Result_Select_Debug(
$queryString,
$parsedQuery,
$queryParser,
$otherQuery,
$explain,
$explainOther,
$timing
);
}
return $result;
}
/**
* Parse data into a documentset
*
* Used for explain and explainOther
*
* @param array $data
* @return array
*/
protected function _parseDocumentSet($data)
{
$docs = array();
foreach ($data as $key => $documentData) {
$details = array();
if (isset($documentData['details']) && is_array($documentData['details'])) {
foreach ($documentData['details'] as $detailData) {
$details[] = new Solarium_Result_Select_Debug_Detail(
$detailData['match'],
$detailData['value'],
$detailData['description']
);
}
}
$docs[$key] = new Solarium_Result_Select_Debug_Document(
$key,
$documentData['match'],
$documentData['value'],
$documentData['description'],
$details);
}
return $docs;
}
/**
* Parse raw timing phase data into a result class
*
* @param string $name
* @param array $data
* @return Solarium_Result_Select_Debug_TimingPhase
*/
protected function _parseTimingPhase($name, $data)
{
$time = 0.0;
$classes = array();
foreach ($data as $key => $timingData) {
switch($key) {
case 'time':
$time = $timingData;
break;
default:
$classes[$key] = $timingData['time'];
}
}
return new Solarium_Result_Select_Debug_TimingPhase($name, $time, $classes);
}
}
\ No newline at end of file
...@@ -125,7 +125,7 @@ class Solarium_Result ...@@ -125,7 +125,7 @@ class Solarium_Result
/** /**
* Get Solr response data * Get Solr response data
* *
* Included a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse. * Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
* *
* @return array * @return array
*/ */
......
...@@ -281,4 +281,16 @@ class Solarium_Result_Select extends Solarium_Result_QueryType ...@@ -281,4 +281,16 @@ class Solarium_Result_Select extends Solarium_Result_QueryType
{ {
return $this->getComponent(Solarium_Query_Select::COMPONENT_STATS); return $this->getComponent(Solarium_Query_Select::COMPONENT_STATS);
} }
/**
* Get debug component result
*
* This is a convenience method that maps presets to getComponent
*
* @return Solarium_Result_Select_Debug
*/
public function getDebug()
{
return $this->getComponent(Solarium_Query_Select::COMPONENT_DEBUG);
}
} }
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_queryString;
/**
* @var string
*/
protected $_parsedQuery;
/**
* @var string
*/
protected $_queryParser;
/**
* @var string
*/
protected $_otherQuery;
/**
* @var Solarium_Result_Select_Debug_DocumentSet
*/
protected $_explain;
/**
* @var Solarium_Result_Select_Debug_DocumentSet
*/
protected $_explainOther;
/**
* @var Solarium_Result_Select_Debug_Timing
*/
protected $_timing;
/**
* Constructor
*
* @param string $queryString
* @param string $parsedQuery
* @param string $queryParser
* @param string $otherQuery
* @param Solarium_Result_Select_Debug_DocumentSet $explain
* @param Solarium_Result_Select_Debug_DocumentSet $explainOther
* @param Solarium_Result_Select_Debug_Timing $timing
*/
public function __construct($queryString, $parsedQuery, $queryParser, $otherQuery, $explain, $explainOther, $timing)
{
$this->_queryString = $queryString;
$this->_parsedQuery = $parsedQuery;
$this->_queryParser = $queryParser;
$this->_otherQuery = $otherQuery;
$this->_explain = $explain;
$this->_explainOther = $explainOther;
$this->_timing = $timing;
}
/**
* Get input querystring
*
* @return string
*/
public function getQueryString()
{
return $this->_queryString;
}
/**
* Get the result of the queryparser
*
* @return string
*/
public function getParsedQuery()
{
return $this->_parsedQuery;
}
/**
* Get the used queryparser
*
* @return string
*/
public function getQueryParser()
{
return $this->_queryParser;
}
/**
* Get other query (only available if set in query)
*
* @return string
*/
public function getOtherQuery()
{
return $this->_otherQuery;
}
/**
* Get explain document set
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getExplain()
{
return $this->_explain;
}
/**
* Get explain other document set (only available if otherquery was set in query)
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getExplainOther()
{
return $this->_explainOther;
}
/**
* Get timing object
*
* @return Solarium_Result_Select_Debug_Timing
*/
public function getTiming()
{
return $this->_timing;
}
/**
* IteratorAggregate implementation
*
* Iterates the explain results
*
* @return Solarium_Result_Select_Debug_DocumentSet
*/
public function getIterator()
{
return $this->_explain;
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_explain);
}
}
\ No newline at end of file
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug detail result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Detail
{
/**
* @var float
*/
protected $_value;
/**
* @var boolean
*/
protected $_match;
/**
* @var string
*/
protected $_description;
/**
* Constructor
*
* @param boolean $match
* @param float $value
* @param string $description
*/
public function __construct($match, $value, $description)
{
$this->_match = $match;
$this->_value = $value;
$this->_description = $description;
}
/**
* Get match status
*
* @return bool
*/
public function getMatch()
{
return $this->_match;
}
/**
* Get match value (score)
*
* @return float
*/
public function getValue()
{
return $this->_value;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->_description;
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug document result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Document extends Solarium_Result_Select_Debug_Detail
implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_key;
/**
* @var array
*/
protected $_details;
/**
* Constructor
*
* @param string $key
* @param boolean $match
* @param float $value
* @param string $description
*/
public function __construct($key, $match, $value, $description, $details)
{
parent::__construct($match, $value, $description);
$this->_key = $key;
$this->_details = $details;
}
/**
* Get key value for this document
*
* @return string
*/
public function getKey()
{
return $this->_key;
}
/**
* Get details
*
* @return array
*/
public function getDetails()
{
return $this->_details;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_details);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_details);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug documentset result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_DocumentSet
implements IteratorAggregate, Countable
{
/**
* Docs array
*
* @var array
*/
protected $_docs;
/**
* Constructor
*
* @param array $docs
* @return void
*/
public function __construct($docs)
{
$this->_docs = $docs;
}
/**
* Get a document by key
*
* @param mixed $key
* @return Solarium_Result_Select_Debug_Document|null
*/
public function getDocument($key)
{
if (isset($this->_docs[$key])) {
return $this->_docs[$key];
} else {
return null;
}
}
/**
* Get all docs
*
* @return array
*/
public function getDocuments()
{
return $this->_docs;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_docs);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_docs);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug timing result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_Timing implements IteratorAggregate, Countable
{
/**
* @var float
*/
protected $_time;
/**
* Timing phase array
*
* @var array
*/
protected $_phases;
/**
* Constructor
*
* @param float $time
* @param array $phases
* @return void
*/
public function __construct($time, $phases)
{
$this->_time = $time;
$this->_phases = $phases;
}
/**
* Get total time
*
* @return float
*/
public function getTime()
{
return $this->_time;
}
/**
* Get a timing phase by key
*
* @param mixed $key
* @return Solarium_Result_Select_Debug_TimingPhase|null
*/
public function getPhase($key)
{
if (isset($this->_phases[$key])) {
return $this->_phases[$key];
} else {
return null;
}
}
/**
* Get timings
*
* @return array
*/
public function getPhases()
{
return $this->_phases;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_phases);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_phases);
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
* @subpackage Result
*/
/**
* Select component debug timing phase result
*
* @package Solarium
* @subpackage Result
*/
class Solarium_Result_Select_Debug_TimingPhase
implements IteratorAggregate, Countable
{
/**
* @var string
*/
protected $_name;
/**
* @var float
*/
protected $_time;
/**
* Timing array
*
* @var array
*/
protected $_timings;
/**
* Constructor
*
* @param string $name
* @param float $time
* @param array $timings
* @return void
*/
public function __construct($name, $time, $timings)
{
$this->_name = $name;
$this->_time = $time;
$this->_timings = $timings;
}
/**
* Get total time
*
* @return float
*/
public function getTime()
{
return $this->_time;
}
/**
* Get a timing by key
*
* @param mixed $key
* @return float|null
*/
public function getTiming($key)
{
if (isset($this->_timings[$key])) {
return $this->_timings[$key];
} else {
return null;
}
}
/**
* Get timings
*
* @return array
*/
public function getTimings()
{
return $this->_timings;
}
/**
* IteratorAggregate implementation
*
* @return ArrayIterator
*/
public function getIterator()
{
return new ArrayIterator($this->_timings);
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
return count($this->_timings);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment