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

Added interfaces (issue #50), also some fixes in unittests

parent 19813a82
...@@ -40,13 +40,13 @@ ...@@ -40,13 +40,13 @@
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable; use Solarium\Core\ConfigurableInterface;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response; use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Endpoint;
/** /**
* Base class for all adapters * Interface for client adapters
* *
* The goal of an adapter is to accept a query, execute it and return the right * The goal of an adapter is to accept a query, execute it and return the right
* result object. This is actually quite a complex task as it involves the * result object. This is actually quite a complex task as it involves the
...@@ -55,28 +55,24 @@ use Solarium\Core\Client\Endpoint; ...@@ -55,28 +55,24 @@ use Solarium\Core\Client\Endpoint;
* The adapter structure allows for varying implementations of this task. * The adapter structure allows for varying implementations of this task.
* *
* Most adapters will use some sort of HTTP client. In that case the * Most adapters will use some sort of HTTP client. In that case the
* Solarium\Client\Request request builders and Solarium\Client\Response * query request builders and query response parsers can be used to simplify
* response parsers can be used to simplify HTTP communication. * HTTP communication.
* See {@link Solarium\Client\Adapter\Http} as an example.
* *
* However an adapter may also implement all logic by itself if needed. * However an adapter may also implement all logic by itself if needed.
* *
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
abstract class Adapter extends Configurable interface AdapterInterface extends ConfigurableInterface
{ {
/** /**
* Execute a request * Execute a request
* *
* Abstract method to require an implementation inside all adapters.
*
* @abstract
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
* @return Response * @return Response
*/ */
abstract public function execute($request, $endpoint); function execute($request, $endpoint);
} }
\ No newline at end of file
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Exception; use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException; use Solarium\Core\Client\HttpException;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
...@@ -53,7 +54,7 @@ use Solarium\Core\Client\Endpoint; ...@@ -53,7 +54,7 @@ use Solarium\Core\Client\Endpoint;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
class Curl extends Adapter class Curl extends Configurable implements AdapterInterface
{ {
/** /**
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Exception; use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException; use Solarium\Core\Client\HttpException;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
...@@ -52,7 +53,7 @@ use Solarium\Core\Client\Endpoint; ...@@ -52,7 +53,7 @@ use Solarium\Core\Client\Endpoint;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
class Http extends Adapter class Http extends Configurable implements AdapterInterface
{ {
/** /**
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Exception; use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException; use Solarium\Core\Client\HttpException;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
...@@ -54,7 +55,7 @@ use Solarium\Core\Client\Endpoint; ...@@ -54,7 +55,7 @@ use Solarium\Core\Client\Endpoint;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
class PeclHttp extends Adapter class PeclHttp extends Configurable implements AdapterInterface
{ {
/** /**
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client; use Solarium\Core\Client;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response; use Solarium\Core\Client\Response;
...@@ -58,7 +59,7 @@ use Solarium\Core\Client\Endpoint; ...@@ -58,7 +59,7 @@ use Solarium\Core\Client\Endpoint;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
class ZendHttp extends Adapter class ZendHttp extends Configurable implements AdapterInterface
{ {
/** /**
......
...@@ -42,9 +42,11 @@ ...@@ -42,9 +42,11 @@
namespace Solarium\Core\Client; namespace Solarium\Core\Client;
use Solarium\Core\Exception; use Solarium\Core\Exception;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
use Solarium\Core\Plugin; use Solarium\Core\PluginInterface;
use Solarium\Core\Query\Query; use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result; use Solarium\Core\Query\Result\ResultInterface;
use Solarium\Core\Client\Adapter\AdapterInterface;
use Solarium\Core\Query\RequestBuilderInterface;
/** /**
* Main interface for interaction with Solr * Main interface for interaction with Solr
...@@ -180,7 +182,7 @@ class Client extends Configurable ...@@ -180,7 +182,7 @@ class Client extends Configurable
* on first use by {@link getAdapter()} based on the 'adapter' entry in * on first use by {@link getAdapter()} based on the 'adapter' entry in
* {@link $options}. This option can be set using {@link setAdapter()} * {@link $options}. This option can be set using {@link setAdapter()}
* *
* @var Adapter\Adapter * @var AdapterInterface
*/ */
protected $adapter; protected $adapter;
...@@ -395,9 +397,7 @@ class Client extends Configurable ...@@ -395,9 +397,7 @@ class Client extends Configurable
/** /**
* Set the adapter * Set the adapter
* *
* The adapter has to be a class that extends * The adapter has to be a class that implements the AdapterInterface
* {@link Solarium\Client\Adapter}.
*
* *
* If a string is passed it is assumed to be the classname and it will be * If a string is passed it is assumed to be the classname and it will be
* instantiated on first use. This requires the availability of the class * instantiated on first use. This requires the availability of the class
...@@ -409,7 +409,7 @@ class Client extends Configurable ...@@ -409,7 +409,7 @@ class Client extends Configurable
* If an adapter instance is passed it will replace the current adapter * If an adapter instance is passed it will replace the current adapter
* immediately, bypassing the lazy loading. * immediately, bypassing the lazy loading.
* *
* @param string|Adapter\Adapter $adapter * @param string|AdapterInterface $adapter
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setAdapter($adapter) public function setAdapter($adapter)
...@@ -417,12 +417,14 @@ class Client extends Configurable ...@@ -417,12 +417,14 @@ class Client extends Configurable
if (is_string($adapter)) { if (is_string($adapter)) {
$this->adapter = null; $this->adapter = null;
return $this->setOption('adapter', $adapter); return $this->setOption('adapter', $adapter);
} else { } else if($adapter instanceof AdapterInterface){
// forward options // forward options
$adapter->setOptions($this->options); $adapter->setOptions($this->options);
// overwrite existing adapter // overwrite existing adapter
$this->adapter = $adapter; $this->adapter = $adapter;
return $this; return $this;
}else{
throw new Exception('Invalid adapter input for setAdapter');
} }
} }
...@@ -442,15 +444,22 @@ class Client extends Configurable ...@@ -442,15 +444,22 @@ class Client extends Configurable
protected function createAdapter() protected function createAdapter()
{ {
$adapterClass = $this->getOption('adapter'); $adapterClass = $this->getOption('adapter');
$this->adapter = new $adapterClass; $adapter = new $adapterClass;
$this->adapter->setOptions($this->getOption('adapteroptions'));
// check interface
if(!($adapter instanceof AdapterInterface)) {
throw new Exception('An adapter must implement the AdapterInterface');
}
$adapter->setOptions($this->getOption('adapteroptions'));
$this->adapter = $adapter;
} }
/** /**
* Get the adapter instance * Get the adapter instance
* *
* If {@see $adapter} doesn't hold an instance a new one will be created by * If {@see $adapter} doesn't hold an instance a new one will be created by
* calling {@see _createAdapter()} * calling {@see createAdapter()}
* *
* @param boolean $autoload * @param boolean $autoload
* @return Adapter\Adapter * @return Adapter\Adapter
...@@ -531,8 +540,8 @@ class Client extends Configurable ...@@ -531,8 +540,8 @@ class Client extends Configurable
$plugin = new $plugin; $plugin = new $plugin;
} }
if (!($plugin instanceof Plugin)) { if (!($plugin instanceof PluginInterface)) {
throw new Exception('All plugins must extend Solarium\Core\Plugin'); throw new Exception('All plugins must implement the PluginInterface');
} }
$plugin->initPlugin($this, $options); $plugin->initPlugin($this, $options);
...@@ -669,16 +678,16 @@ class Client extends Configurable ...@@ -669,16 +678,16 @@ class Client extends Configurable
/** /**
* Creates a request based on a query instance * Creates a request based on a query instance
* *
* @param Query $query * @param QueryInterface $query
* @return Request * @return Request
*/ */
public function createRequest($query) public function createRequest(QueryInterface $query)
{ {
$pluginResult = $this->callPlugins('preCreateRequest', array($query), true); $pluginResult = $this->callPlugins('preCreateRequest', array($query), true);
if($pluginResult !== null) return $pluginResult; if($pluginResult !== null) return $pluginResult;
$requestBuilder = $query->getRequestBuilder(); $requestBuilder = $query->getRequestBuilder();
if (!$requestBuilder) { if (!$requestBuilder || !($requestBuilder instanceof RequestBuilderInterface)) {
throw new Exception('No requestbuilder returned by querytype: '. $query->getType()); throw new Exception('No requestbuilder returned by querytype: '. $query->getType());
} }
...@@ -692,11 +701,11 @@ class Client extends Configurable ...@@ -692,11 +701,11 @@ class Client extends Configurable
/** /**
* Creates a result object * Creates a result object
* *
* @param Query $query * @param QueryInterface $query
* @param array Response $response * @param array Response $response
* @return Result * @return ResultInterface
*/ */
public function createResult($query, $response) public function createResult(QueryInterface $query, $response)
{ {
$pluginResult = $this->callPlugins('preCreateResult', array($query, $response), true); $pluginResult = $this->callPlugins('preCreateResult', array($query, $response), true);
if($pluginResult !== null) return $pluginResult; if($pluginResult !== null) return $pluginResult;
...@@ -704,6 +713,10 @@ class Client extends Configurable ...@@ -704,6 +713,10 @@ class Client extends Configurable
$resultClass = $query->getResultClass(); $resultClass = $query->getResultClass();
$result = new $resultClass($this, $query, $response); $result = new $resultClass($this, $query, $response);
if (!($result instanceof ResultInterface)) {
throw new Exception('Result class must implement the ResultInterface');
}
$this->callPlugins('postCreateResult', array($query, $response, $result)); $this->callPlugins('postCreateResult', array($query, $response, $result));
return $result; return $result;
...@@ -712,11 +725,11 @@ class Client extends Configurable ...@@ -712,11 +725,11 @@ class Client extends Configurable
/** /**
* Execute a query * Execute a query
* *
* @param Query * @param QueryInterface
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Result * @return ResultInterface
*/ */
public function execute($query, $endpoint = null) public function execute(QueryInterface $query, $endpoint = null)
{ {
$pluginResult = $this->callPlugins('preExecute', array($query), true); $pluginResult = $this->callPlugins('preExecute', array($query), true);
if($pluginResult !== null) return $pluginResult; if($pluginResult !== null) return $pluginResult;
...@@ -775,7 +788,7 @@ class Client extends Configurable ...@@ -775,7 +788,7 @@ class Client extends Configurable
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Solarium\Query\Ping\Result * @return Solarium\Query\Ping\Result
*/ */
public function ping($query, $endpoint = null) public function ping(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -801,7 +814,7 @@ class Client extends Configurable ...@@ -801,7 +814,7 @@ class Client extends Configurable
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Solarium\Query\Update\Result * @return Solarium\Query\Update\Result
*/ */
public function update($query, $endpoint = null) public function update(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -826,7 +839,7 @@ class Client extends Configurable ...@@ -826,7 +839,7 @@ class Client extends Configurable
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Solarium\Query\Result\Select\Result * @return Solarium\Query\Result\Select\Result
*/ */
public function select($query, $endpoint = null) public function select(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -851,7 +864,7 @@ class Client extends Configurable ...@@ -851,7 +864,7 @@ class Client extends Configurable
* @param Endpoint * @param Endpoint
* @return Solarium\Query\MoreLikeThis\Result * @return Solarium\Query\MoreLikeThis\Result
*/ */
public function moreLikeThis($query, $endpoint = null) public function moreLikeThis(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -866,7 +879,7 @@ class Client extends Configurable ...@@ -866,7 +879,7 @@ class Client extends Configurable
* @param Endpoint * @param Endpoint
* @return Solarium\Query\Analysis\Result\Document|Solarium\Query\Analysis\Result\Field * @return Solarium\Query\Analysis\Result\Document|Solarium\Query\Analysis\Result\Field
*/ */
public function analyze($query, $endpoint = null) public function analyze(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -881,7 +894,7 @@ class Client extends Configurable ...@@ -881,7 +894,7 @@ class Client extends Configurable
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Solarium\Query\Terms\Result * @return Solarium\Query\Terms\Result
*/ */
public function terms($query, $endpoint = null) public function terms(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -896,7 +909,7 @@ class Client extends Configurable ...@@ -896,7 +909,7 @@ class Client extends Configurable
* @param Endpoint|string|null * @param Endpoint|string|null
* @return Solarium\Query\Suggester\Result * @return Solarium\Query\Suggester\Result
*/ */
public function suggester($query, $endpoint = null) public function suggester(QueryInterface $query, $endpoint = null)
{ {
return $this->execute($query, $endpoint); return $this->execute($query, $endpoint);
} }
...@@ -922,6 +935,10 @@ class Client extends Configurable ...@@ -922,6 +935,10 @@ class Client extends Configurable
$class = $this->queryTypes[$type]; $class = $this->queryTypes[$type];
$query = new $class($options); $query = new $class($options);
if (!($query instanceof QueryInterface)) {
throw new Exception('All query classes must implement the QueryInterface');
}
$this->callPlugins('postCreateQuery', array($type, $options, $query)); $this->callPlugins('postCreateQuery', array($type, $options, $query));
return $query; return $query;
......
...@@ -50,7 +50,7 @@ namespace Solarium\Core; ...@@ -50,7 +50,7 @@ namespace Solarium\Core;
* @package Solarium * @package Solarium
* @subpackage Plugin * @subpackage Plugin
*/ */
class Configurable class Configurable implements ConfigurableInterface
{ {
/** /**
......
<?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
*/
/**
* @namespace
*/
namespace Solarium\Core;
/**
* Interface for configurable classes
*
* All classes implementing this interface are configurable using the constructor or
* setOption calls. This is the base for many Solarium classes, providing a
* uniform interface for various models.
*
* @package Solarium
* @subpackage Plugin
*/
interface ConfigurableInterface
{
/**
* Constructor
*
* If options are passed they will be merged with {@link $options} using
* the {@link setOptions()} method.
*
* After handling the options the {@link _init()} method is called.
*
* @throws Exception
* @param array|\Zend_Config $options
* @return void
*/
function __construct($options = null);
/**
* Set options
*
* If $options is an object it will be converted into an array by called
* it's toArray method. This is compatible with the Zend_Config classes in
* Zend Framework, but can also easily be implemented in any other object.
*
* @throws Exception
* @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*
* @return void
*/
function setOptions($options, $overwrite = false);
/**
* Get an option value by name
*
* If the option is empty or not set a NULL value will be returned.
*
* @param string $name
* @return mixed
*/
function getOption($name);
/**
* Get all options
*
* @return array
*/
function getOptions();
}
\ No newline at end of file
...@@ -45,7 +45,7 @@ use Solarium\Core\Configurable; ...@@ -45,7 +45,7 @@ use Solarium\Core\Configurable;
use Solarium\Core\Query\Query; use Solarium\Core\Query\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response; use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result; use Solarium\Core\Query\Result\Result;
/** /**
* Base class for plugins * Base class for plugins
...@@ -53,7 +53,7 @@ use Solarium\Core\Query\Result; ...@@ -53,7 +53,7 @@ use Solarium\Core\Query\Result;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
abstract class Plugin extends Configurable abstract class Plugin extends Configurable implements PluginInterface
{ {
/** /**
......
<?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 Core
*/
/**
* @namespace
*/
namespace Solarium\Core;
use Solarium\Core\Client\Client;
use Solarium\Core\Query\Query;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\Result;
/**
* Interface for plugins
*
* @package Solarium
* @subpackage Core
*/
interface PluginInterface extends ConfigurableInterface
{
/**
* Initialize
*
* This method is called when the plugin is registered to a client instance
*
* @param Client $client
* @param array $options
*/
function initPlugin($client, $options);
/**
* preCreateRequest hook
*
* @param Query $query
* @return void|Request
*/
function preCreateRequest($query);
/**
* postCreateRequest hook
*
* @param Query $query
* @param Request $request
* @return void
*/
function postCreateRequest($query, $request);
/**
* preExecuteRequest hook
*
* @param Request $request
* @return void|Response
*/
function preExecuteRequest($request);
/**
* postExecuteRequest hook
*
* @param Request $request
* @param Response $response
* @return void
*/
function postExecuteRequest($request, $response);
/**
* preCreateResult hook
*
* @param Query $query
* @param Response $response
* @return void|Result
*/
function preCreateResult($query, $response);
/**
* postCreateResult hook
*
* @param Query $query
* @param Response $response
* @param Result $result
* @return void
*/
function postCreateResult($query, $response, $result);
/**
* preExecute hook
*
* @param Query $query
* @return void|Result
*/
function preExecute($query);
/**
* postExecute hook
*
* @param Query $query
* @param Result $result
* @return void
*/
function postExecute($query, $result);
/**
* preCreateQuery hook
*
* @param string $type
* @param mixed $options
* @return void|Query
*/
function preCreateQuery($type, $options);
/**
* postCreateQuery hook
*
* @param string $type
* @param mixed $options
* @param Query
* @return void
*/
function postCreateQuery($type, $options, $query);
}
\ No newline at end of file
...@@ -49,7 +49,7 @@ use Solarium\Core\Configurable; ...@@ -49,7 +49,7 @@ use Solarium\Core\Configurable;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
abstract class Query extends Configurable abstract class Query extends Configurable implements QueryInterface
{ {
/** /**
...@@ -66,28 +66,6 @@ abstract class Query extends Configurable ...@@ -66,28 +66,6 @@ abstract class Query extends Configurable
*/ */
protected $params = array(); protected $params = array();
/**
* Get type for this query
*
* @return string
*/
abstract public function getType();
/**
* Get the requestbuilder class for this query
*
* @return object
*/
abstract public function getRequestBuilder();
/**
* Get the response parser class for this query
*
* @return object
*/
abstract public function getResponseParser();
/** /**
* Set handler option * Set handler option
* *
......
<?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 Query
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
use Solarium\Core\Query\Helper;
use Solarium\Core\ConfigurableInterface;
/**
* Query interface
*
* @package Solarium
* @subpackage Core
*/
interface QueryInterface extends ConfigurableInterface
{
/**
* Get type for this query
*
* @return string
*/
function getType();
/**
* Get the requestbuilder class for this query
*
* @return object
*/
function getRequestBuilder();
/**
* Get the response parser class for this query
*
* @return ResponseParserInterface
*/
function getResponseParser();
/**
* Set handler option
*
* @param string $handler
* @return self Provides fluent interface
*/
function setHandler($handler);
/**
* Get handler option
*
* @return string
*/
function getHandler();
/**
* Set resultclass option
*
* If you set a custom result class it must be available through autoloading
* or a manual require before calling this method. This is your
* responsibility.
*
* Also you need to make sure this class implements the ResultInterface
*
* @param string $classname
* @return self Provides fluent interface
*/
function setResultClass($classname);
/**
* Get resultclass option
*
* @return string
*/
function getResultClass();
/**
* Get a helper instance
*
* @return Helper
*/
function getHelper();
/**
* Add extra params to the request
*
* Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get
*
* @param string $name
* @param string $value
* @return self Provides fluent interface
*/
function addParam($name, $value);
/**
* Get extra params
*
* @return array
*/
public function getParams();
}
\ No newline at end of file
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
use Solarium\Core\Query\Query; use Solarium\Core\Query\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\QueryInterface;
/** /**
* Class for building Solarium client requests * Class for building Solarium client requests
...@@ -49,7 +50,7 @@ use Solarium\Core\Client\Request; ...@@ -49,7 +50,7 @@ use Solarium\Core\Client\Request;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
abstract class RequestBuilder abstract class RequestBuilder implements RequestBuilderInterface
{ {
/** /**
...@@ -58,7 +59,7 @@ abstract class RequestBuilder ...@@ -58,7 +59,7 @@ abstract class RequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = new Request; $request = new Request;
$request->setHandler($query->getHandler()); $request->setHandler($query->getHandler());
......
<?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 Core
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Client\Request;
/**
* Interface for requestbuilders
*
* @package Solarium
* @subpackage Core
*/
interface RequestBuilderInterface
{
/**
* Build request for a select query
*
* @param QueryInterface $query
* @return Request
*/
function build(QueryInterface $query);
}
\ No newline at end of file
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
/** /**
* Base class for handling Solr response data * Interface for response parsers
* *
* Most {@link Solarium\Client\Adapter} implementations will use HTTP for * Most {@link Solarium\Client\Adapter} implementations will use HTTP for
* communicating with Solr. While the HTTP part is adapter-specific, the parsing * communicating with Solr. While the HTTP part is adapter-specific, the parsing
...@@ -53,22 +53,17 @@ namespace Solarium\Core\Query; ...@@ -53,22 +53,17 @@ namespace Solarium\Core\Query;
* @package Solarium * @package Solarium
* @subpackage Core * @subpackage Core
*/ */
abstract class ResponseParser interface ResponseParserInterface
{ {
/** /**
* Get a Solarium\Result instance for the given data * Get a Result object for the given data
* *
* When this method is called the actual response parsing is started. * When this method is called the actual response parsing is started.
* *
* @internal Must be implemented in descendents because this parsing is
* query specific.
*
* @abstract
*
* @param Result\Result $result * @param Result\Result $result
* @return mixed * @return mixed
*/ */
abstract function parse($result); function parse($result);
} }
\ No newline at end of file
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
*/ */
namespace Solarium\Core\Query\Result; namespace Solarium\Core\Query\Result;
use Solarium\Core\Exception; use Solarium\Core\Exception;
use Solarium\Core\Query\ResponseParserInterface;
/** /**
* QueryType result * QueryType result
...@@ -70,7 +71,7 @@ class QueryType extends Result ...@@ -70,7 +71,7 @@ class QueryType extends Result
if (!$this->parsed) { if (!$this->parsed) {
$responseParser = $this->query->getResponseParser(); $responseParser = $this->query->getResponseParser();
if (!$responseParser) { if (!$responseParser || !($responseParser instanceof ResponseParserInterface)) {
throw new Exception('No responseparser returned by querytype: '. $this->query->getType()); throw new Exception('No responseparser returned by querytype: '. $this->query->getType());
} }
......
...@@ -56,7 +56,7 @@ use Solarium\Core\Query\Query; ...@@ -56,7 +56,7 @@ use Solarium\Core\Query\Query;
* @package Solarium * @package Solarium
* @subpackage Result * @subpackage Result
*/ */
class Result class Result implements ResultInterface
{ {
/** /**
......
<?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
*/
/**
* @namespace
*/
namespace Solarium\Core\Query\Result;
use Solarium\Core\Client\Response;
use Solarium\Core\Query\Query;
/**
* Query result interface
*
* @package Solarium
* @subpackage Result
*/
interface ResultInterface
{
/**
* Get response object
*
* This is the raw HTTP response object, not the parsed data!
*
* @return Response
*/
function getResponse();
/**
* Get query instance
*
* @return Query
*/
function getQuery();
/**
* Get Solr response data
*
* Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
*
* @return array
*/
function getData();
}
\ No newline at end of file
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
namespace Solarium\Query\Analysis\RequestBuilder; namespace Solarium\Query\Analysis\RequestBuilder;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a document analysis request * Build a document analysis request
...@@ -58,7 +59,7 @@ class Document extends BaseRequestBuilder ...@@ -58,7 +59,7 @@ class Document extends BaseRequestBuilder
* @param Document $query * @param Document $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->setRawData($this->getRawData($query)); $request->setRawData($this->getRawData($query));
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
namespace Solarium\Query\Analysis\RequestBuilder; namespace Solarium\Query\Analysis\RequestBuilder;
use Solarium\Query\Analysis\Query\Field as QueryField; use Solarium\Query\Analysis\Query\Field as QueryField;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a field analysis request * Build a field analysis request
* *
...@@ -57,7 +59,7 @@ class Field extends RequestBuilder ...@@ -57,7 +59,7 @@ class Field extends RequestBuilder
* @param QueryField $query * @param QueryField $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
......
...@@ -44,6 +44,7 @@ use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; ...@@ -44,6 +44,7 @@ use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Query\Analysis\Query\Query; use Solarium\Query\Analysis\Query\Query;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build an analysis request * Build an analysis request
...@@ -60,7 +61,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -60,7 +61,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->addParam('analysis.query', $query->getQuery()); $request->addParam('analysis.query', $query->getQuery());
......
...@@ -42,15 +42,15 @@ ...@@ -42,15 +42,15 @@
namespace Solarium\Query\Analysis\ResponseParser; namespace Solarium\Query\Analysis\ResponseParser;
use Solarium\Core\Query\Result\Result; use Solarium\Core\Query\Result\Result;
use Solarium\Query\Analysis\Result as AnalysisResult; use Solarium\Query\Analysis\Result as AnalysisResult;
use Solarium\Core\Query\ResponseParser as BaseResponseParser; use Solarium\Core\Query\ResponseParserInterface;
/** /**
* Parse document analysis response data * Parse document analysis response data
* *
* @package Solarium * @package Solarium
* @subpackage QueryType * @subpackage Query
*/ */
class Field extends BaseResponseParser class Field implements ResponseParserInterface
{ {
/** /**
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
namespace Solarium\Query\MoreLikeThis; namespace Solarium\Query\MoreLikeThis;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Query\Select\RequestBuilder\RequestBuilder as SelectRequestBuilder; use Solarium\Query\Select\RequestBuilder\RequestBuilder as SelectRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a MoreLikeThis request * Build a MoreLikeThis request
...@@ -61,7 +62,7 @@ class RequestBuilder extends SelectRequestBuilder ...@@ -61,7 +62,7 @@ class RequestBuilder extends SelectRequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
namespace Solarium\Query\Ping; namespace Solarium\Query\Ping;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a ping request * Build a ping request
...@@ -58,7 +59,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -58,7 +59,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->setMethod(Request::METHOD_GET); $request->setMethod(Request::METHOD_GET);
......
...@@ -43,6 +43,7 @@ namespace Solarium\Query\Select\RequestBuilder; ...@@ -43,6 +43,7 @@ namespace Solarium\Query\Select\RequestBuilder;
use Solarium\Query\Select\Query\Query as SelectQuery; use Solarium\Query\Select\Query\Query as SelectQuery;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a select request * Build a select request
...@@ -59,7 +60,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -59,7 +60,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param SelectQuery $query * @param SelectQuery $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Query\Select\ResponseParser; namespace Solarium\Query\Select\ResponseParser;
use Solarium\Core\Query\ResponseParser as BaseResponseParser; use Solarium\Core\Query\ResponseParserInterface;
use Solarium\Query\Select\Result\Result; use Solarium\Query\Select\Result\Result;
/** /**
...@@ -49,7 +49,7 @@ use Solarium\Query\Select\Result\Result; ...@@ -49,7 +49,7 @@ use Solarium\Query\Select\Result\Result;
* @package Solarium * @package Solarium
* @subpackage Query * @subpackage Query
*/ */
class ResponseParser extends BaseResponseParser class ResponseParser implements ResponseParserInterface
{ {
/** /**
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
namespace Solarium\Query\Suggester; namespace Solarium\Query\Suggester;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a Suggester query request * Build a Suggester query request
...@@ -58,7 +59,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -58,7 +59,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->addParam('spellcheck', 'true'); $request->addParam('spellcheck', 'true');
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
*/ */
namespace Solarium\Query\Suggester; namespace Solarium\Query\Suggester;
use Solarium\Client; use Solarium\Client;
use Solarium\Core\Query\ResponseParser as BaseResponseParser; use Solarium\Core\Query\ResponseParserInterface;
/** /**
* Parse Suggester response data * Parse Suggester response data
...@@ -50,7 +50,7 @@ use Solarium\Core\Query\ResponseParser as BaseResponseParser; ...@@ -50,7 +50,7 @@ use Solarium\Core\Query\ResponseParser as BaseResponseParser;
* @package Solarium * @package Solarium
* @subpackage QueryType * @subpackage QueryType
*/ */
class ResponseParser extends BaseResponseParser class ResponseParser implements ResponseParserInterface
{ {
/** /**
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
namespace Solarium\Query\Terms; namespace Solarium\Query\Terms;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build a Terms query request * Build a Terms query request
...@@ -61,7 +62,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -61,7 +62,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param Query $query * @param Query $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->setHandler($query->getHandler()); $request->setHandler($query->getHandler());
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Query\Terms; namespace Solarium\Query\Terms;
use Solarium\Core\Query\ResponseParser as BaseResponseParser; use Solarium\Core\Query\ResponseParserInterface;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
/** /**
...@@ -50,7 +50,7 @@ use Solarium\Core\Client\Request; ...@@ -50,7 +50,7 @@ use Solarium\Core\Client\Request;
* @package Solarium * @package Solarium
* @subpackage QueryType * @subpackage QueryType
*/ */
class ResponseParser extends BaseResponseParser class ResponseParser implements ResponseParserInterface
{ {
/** /**
......
...@@ -45,6 +45,7 @@ use Solarium\Client; ...@@ -45,6 +45,7 @@ use Solarium\Client;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
use Solarium\Query\Update\Query\Query as UpdateQuery; use Solarium\Query\Update\Query\Query as UpdateQuery;
use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder; use Solarium\Core\Query\RequestBuilder as BaseRequestBuilder;
use Solarium\Core\Query\QueryInterface;
/** /**
* Build an update request * Build an update request
...@@ -61,7 +62,7 @@ class RequestBuilder extends BaseRequestBuilder ...@@ -61,7 +62,7 @@ class RequestBuilder extends BaseRequestBuilder
* @param UpdateQuery $query * @param UpdateQuery $query
* @return Request * @return Request
*/ */
public function build($query) public function build(QueryInterface $query)
{ {
$request = parent::build($query); $request = parent::build($query);
$request->setMethod(Request::METHOD_POST); $request->setMethod(Request::METHOD_POST);
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* @namespace * @namespace
*/ */
namespace Solarium\Query\Update; namespace Solarium\Query\Update;
use Solarium\Core\Query\ResponseParser as BaseResponseParser; use Solarium\Core\Query\ResponseParserInterface;
/** /**
* Parse update response data * Parse update response data
...@@ -48,7 +48,7 @@ use Solarium\Core\Query\ResponseParser as BaseResponseParser; ...@@ -48,7 +48,7 @@ use Solarium\Core\Query\ResponseParser as BaseResponseParser;
* @package Solarium * @package Solarium
* @subpackage QueryType * @subpackage QueryType
*/ */
class ResponseParser extends BaseResponseParser class ResponseParser implements ResponseParserInterface
{ {
/** /**
......
...@@ -466,7 +466,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -466,7 +466,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{ {
$queryStub = $this->getMock('Solarium\Query\Select\Query\Query'); $queryStub = $this->getMock('Solarium\Query\Select\Query\Query');
$observer = $this->getMock('Solarium\Core\Client\RequestBuilder', array('build')); $observer = $this->getMock('Solarium\Core\Query\RequestBuilder', array('build'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('build') ->method('build')
->with($this->equalTo($queryStub)); ->with($this->equalTo($queryStub));
...@@ -706,7 +706,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -706,7 +706,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $dummyResponse = 'dummyresponse';
$observer = $this->getMock('Solarium\Core\Client\Adapter\Adapter', array('execute')); $observer = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$observer->expects($this->once()) $observer->expects($this->once())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
...@@ -726,7 +726,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -726,7 +726,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $dummyResponse = 'dummyresponse';
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Adapter', array('execute')); $mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->once()) $mockAdapter->expects($this->once())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
...@@ -747,7 +747,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase ...@@ -747,7 +747,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$request = new Request(); $request = new Request();
$dummyResponse = 'dummyresponse'; $dummyResponse = 'dummyresponse';
$mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Adapter', array('execute')); $mockAdapter = $this->getMock('Solarium\Core\Client\Adapter\Http', array('execute'));
$mockAdapter->expects($this->any()) $mockAdapter->expects($this->any())
->method('execute') ->method('execute')
->with($this->equalTo($request)) ->with($this->equalTo($request))
......
...@@ -152,7 +152,7 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase ...@@ -152,7 +152,7 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$data = array('id' => '123', 'name' => 'test'); $data = array('id' => '123', 'name' => 'test');
$doc = new Document($data); $doc = new Document($data);
$mockUpdate = $this->getMock('Solarium\Core\Query\Update\Query\Query', array('addDocuments', 'addCommit')); $mockUpdate = $this->getMock('Solarium\Query\Update\Query\Query', array('addDocuments', 'addCommit'));
$mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true)); $mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true));
$mockUpdate->expects($this->once())->method('addCommit')->with($this->equalTo(false),$this->equalTo(true),$this->equalTo(false)); $mockUpdate->expects($this->once())->method('addCommit')->with($this->equalTo(false),$this->equalTo(true),$this->equalTo(false));
......
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