Commit 337640c4 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'wickedOne-phpcs-fix' into develop

parents 4ea1f324 c5fc5255
...@@ -2,4 +2,4 @@ build ...@@ -2,4 +2,4 @@ build
phpunit.xml phpunit.xml
composer.phar composer.phar
composer.lock composer.lock
vendor vendor
\ No newline at end of file
...@@ -3,7 +3,7 @@ require(__DIR__.'/init.php'); ...@@ -3,7 +3,7 @@ require(__DIR__.'/init.php');
use Solarium\Core\Event\Events; use Solarium\Core\Event\Events;
// this very simple plugin shows a timing for each event and display some request debug info // this very simple plugin shows a timing for each event and display some request debug info
class BasicDebug extends Solarium\Core\Plugin\Plugin class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
{ {
protected $start; protected $start;
protected $output = array(); protected $output = array();
......
<?php <?php
require(__DIR__.'/init.php'); require(__DIR__.'/init.php');
use Solarium\Client; use Solarium\Client;
use Solarium\Core\Plugin\Plugin; use Solarium\Core\Plugin\AbstractPlugin;
use Solarium\QueryType\Select\Query\Query as Select; use Solarium\QueryType\Select\Query\Query as Select;
// This is a custom query class that could have some customized logic // This is a custom query class that could have some customized logic
...@@ -11,7 +11,7 @@ class MyQuery extends Select ...@@ -11,7 +11,7 @@ class MyQuery extends Select
} }
// this very simple plugin that modifies the default querytype mapping // this very simple plugin that modifies the default querytype mapping
class QueryCustomizer extends Plugin class QueryCustomizer extends AbstractPlugin
{ {
public function initPlugin($client, $options) public function initPlugin($client, $options)
{ {
......
...@@ -30,16 +30,18 @@ ...@@ -30,16 +30,18 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium; namespace Solarium;
/** /**
* Autoloader * Autoloader.
* *
* This class is included to allow for easy usage of Solarium in environments missing a PSR-O autoloader. * This class is included to allow for easy usage of Solarium in environments missing a PSR-O autoloader.
* *
...@@ -52,7 +54,7 @@ namespace Solarium; ...@@ -52,7 +54,7 @@ namespace Solarium;
class Autoloader class Autoloader
{ {
/** /**
* Register the Solarium autoloader * Register the Solarium autoloader.
* *
* The autoloader only acts for classnames that start with 'Solarium'. It * The autoloader only acts for classnames that start with 'Solarium'. It
* will be appended to any other autoloaders already registered. * will be appended to any other autoloaders already registered.
...@@ -61,36 +63,34 @@ class Autoloader ...@@ -61,36 +63,34 @@ class Autoloader
* you want to use multiple autoloaders please use spl_autoload_register. * you want to use multiple autoloaders please use spl_autoload_register.
* *
* @static * @static
* @return void
*/ */
public static function register() public static function register()
{ {
spl_autoload_register(array(new self, 'load')); spl_autoload_register(array(new self(), 'load'));
} }
/** /**
* Autoload a class * Autoload a class.
* *
* This method is automatically called after registering this autoloader. * This method is automatically called after registering this autoloader.
* The autoloader only acts for classnames that start with 'Solarium'. * The autoloader only acts for classnames that start with 'Solarium'.
* *
* @static * @static
* @param string $class *
* @return void * @param string $class
*/ */
public static function load($class) public static function load($class)
{ {
if (substr($class, 0, 8) == 'Solarium') { if (substr($class, 0, 8) == 'Solarium') {
$class = str_replace( $class = str_replace(
array('Solarium', '\\'), array('Solarium', '\\'),
array('', '/'), array('', '/'),
$class $class
); );
$file = dirname(__FILE__) . $class . '.php'; $file = dirname(__FILE__).$class.'.php';
require($file); require $file;
} }
} }
} }
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium; namespace Solarium;
use Solarium\Core\Client\Client as CoreClient; use Solarium\Core\Client\Client as CoreClient;
...@@ -47,7 +49,7 @@ use Solarium\Core\Client\Client as CoreClient; ...@@ -47,7 +49,7 @@ use Solarium\Core\Client\Client as CoreClient;
class Client extends CoreClient class Client extends CoreClient
{ {
/** /**
* Version number of the Solarium library * Version number of the Solarium library.
* *
* The version is built up in this format: major.minor.mini * The version is built up in this format: major.minor.mini
* *
...@@ -73,7 +75,7 @@ class Client extends CoreClient ...@@ -73,7 +75,7 @@ class Client extends CoreClient
const VERSION = '3.2.0'; const VERSION = '3.2.0';
/** /**
* Check for an exact version * Check for an exact version.
* *
* This method can check for all three versioning levels, but they are * This method can check for all three versioning levels, but they are
* optional. If you only care for major and minor versions you can use * optional. If you only care for major and minor versions you can use
...@@ -96,7 +98,8 @@ class Client extends CoreClient ...@@ -96,7 +98,8 @@ class Client extends CoreClient
* @internal a string compare is used instead of version_compare because * @internal a string compare is used instead of version_compare because
* version_compare returns false for a compare of 1.0.0 with 1.0 * version_compare returns false for a compare of 1.0.0 with 1.0
* *
* @param string $version * @param string $version
*
* @return boolean * @return boolean
*/ */
public static function checkExact($version) public static function checkExact($version)
...@@ -105,7 +108,7 @@ class Client extends CoreClient ...@@ -105,7 +108,7 @@ class Client extends CoreClient
} }
/** /**
* Check for a minimal version * Check for a minimal version.
* *
* This method can check for all three versioning levels, but they are * This method can check for all three versioning levels, but they are
* optional. If you only care for major and minor versions you can use * optional. If you only care for major and minor versions you can use
...@@ -123,7 +126,8 @@ class Client extends CoreClient ...@@ -123,7 +126,8 @@ class Client extends CoreClient
* - 2 (the actual version is lower) * - 2 (the actual version is lower)
* - 1.3 (the actual version is lower) * - 1.3 (the actual version is lower)
* *
* @param string $version * @param string $version
*
* @return boolean * @return boolean
*/ */
public static function checkMinimal($version) public static function checkMinimal($version)
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\ConfigurableInterface; use Solarium\Core\ConfigurableInterface;
...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response; ...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Endpoint;
/** /**
* Interface for client 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
...@@ -61,10 +63,11 @@ use Solarium\Core\Client\Endpoint; ...@@ -61,10 +63,11 @@ use Solarium\Core\Client\Endpoint;
interface AdapterInterface extends ConfigurableInterface interface AdapterInterface extends ConfigurableInterface
{ {
/** /**
* Execute a request * Execute a request.
*
* @param Request $request
* @param Endpoint $endpoint
* *
* @param Request $request
* @param Endpoint $endpoint
* @return Response * @return Response
*/ */
public function execute($request, $endpoint); public function execute($request, $endpoint);
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
...@@ -47,35 +49,18 @@ use Solarium\Exception\RuntimeException; ...@@ -47,35 +49,18 @@ use Solarium\Exception\RuntimeException;
use Solarium\Exception\HttpException; use Solarium\Exception\HttpException;
/** /**
* cURL HTTP adapter * cURL HTTP adapter.
* *
* @author Intervals <info@myintervals.com> * @author Intervals <info@myintervals.com>
*/ */
class Curl extends Configurable implements AdapterInterface class Curl extends Configurable implements AdapterInterface
{ {
/** /**
* Initialization hook * Execute a Solr request using the cURL Http.
*
* Checks the availability of Curl_http
* *
* @throws RuntimeException * @param Request $request
*/ * @param Endpoint $endpoint
protected function init()
{
// @codeCoverageIgnoreStart
if (!function_exists('curl_init')) {
throw new RuntimeException('cURL is not available, install it to use the CurlHttp adapter');
}
parent::init();
// @codeCoverageIgnoreEnd
}
/**
* Execute a Solr request using the cURL Http
* *
* @param Request $request
* @param Endpoint $endpoint
* @return Response * @return Response
*/ */
public function execute($request, $endpoint) public function execute($request, $endpoint)
...@@ -84,27 +69,11 @@ class Curl extends Configurable implements AdapterInterface ...@@ -84,27 +69,11 @@ class Curl extends Configurable implements AdapterInterface
} }
/** /**
* Execute request * Get the response for a curl handle.
* *
* @param Request $request * @param resource $handle
* @param Endpoint $endpoint * @param string $httpResponse
* @return Response
*/
protected function getData($request, $endpoint)
{
// @codeCoverageIgnoreStart
$handle = $this->createHandle($request, $endpoint);
$httpResponse = curl_exec($handle);
return $this->getResponse($handle, $httpResponse);
// @codeCoverageIgnoreEnd
}
/**
* Get the response for a curl handle
* *
* @param resource $handle
* @param string $httpResponse
* @return Response * @return Response
*/ */
public function getResponse($handle, $httpResponse) public function getResponse($handle, $httpResponse)
...@@ -114,7 +83,7 @@ class Curl extends Configurable implements AdapterInterface ...@@ -114,7 +83,7 @@ class Curl extends Configurable implements AdapterInterface
$data = $httpResponse; $data = $httpResponse;
$info = curl_getinfo($handle); $info = curl_getinfo($handle);
$headers = array(); $headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK'; $headers[] = 'HTTP/1.1 '.$info['http_code'].' OK';
} else { } else {
$headers = array(); $headers = array();
$data = ''; $data = '';
...@@ -128,17 +97,19 @@ class Curl extends Configurable implements AdapterInterface ...@@ -128,17 +97,19 @@ class Curl extends Configurable implements AdapterInterface
} }
/** /**
* Create curl handle for a request * Create curl handle for a request.
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @param Request $request *
* @param Endpoint $endpoint * @param Request $request
* @param Endpoint $endpoint
*
* @return resource * @return resource
*/ */
public function createHandle($request, $endpoint) public function createHandle($request, $endpoint)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$uri = $endpoint->getBaseUri() . $request->getUri(); $uri = $endpoint->getBaseUri().$request->getUri();
$method = $request->getMethod(); $method = $request->getMethod();
$options = $this->createOptions($request, $endpoint); $options = $this->createOptions($request, $endpoint);
...@@ -166,14 +137,14 @@ class Curl extends Configurable implements AdapterInterface ...@@ -166,14 +137,14 @@ class Curl extends Configurable implements AdapterInterface
} }
if (!empty($authData['username']) && !empty($authData['password'])) { if (!empty($authData['username']) && !empty($authData['password'])) {
curl_setopt($handler, CURLOPT_USERPWD, $authData['username']. ':' . $authData['password']); curl_setopt($handler, CURLOPT_USERPWD, $authData['username'].':'.$authData['password']);
curl_setopt($handler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($handler, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
} }
if (count($options['headers'])) { if (count($options['headers'])) {
$headers = array(); $headers = array();
foreach ($options['headers'] as $key => $value) { foreach ($options['headers'] as $key => $value) {
$headers[] = $key . ": " . $value; $headers[] = $key.": ".$value;
} }
curl_setopt($handler, CURLOPT_HTTPHEADER, $headers); curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
} }
...@@ -203,18 +174,73 @@ class Curl extends Configurable implements AdapterInterface ...@@ -203,18 +174,73 @@ class Curl extends Configurable implements AdapterInterface
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/**
* Check result of a request.
*
* @throws HttpException
*
* @param string $data
* @param array $headers
* @param resource $handle
*/
public function check($data, $headers, $handle)
{
// if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible.
if (empty($data) && count($headers) == 0) {
throw new HttpException('HTTP request failed, '.curl_error($handle));
}
}
/**
* Execute request.
*
* @param Request $request
* @param Endpoint $endpoint
*
* @return Response
*/
protected function getData($request, $endpoint)
{
// @codeCoverageIgnoreStart
$handle = $this->createHandle($request, $endpoint);
$httpResponse = curl_exec($handle);
return $this->getResponse($handle, $httpResponse);
// @codeCoverageIgnoreEnd
}
/**
* Initialization hook.
*
* Checks the availability of Curl_http
*
* @throws RuntimeException
*/
protected function init()
{
// @codeCoverageIgnoreStart
if (!function_exists('curl_init')) {
throw new RuntimeException('cURL is not available, install it to use the CurlHttp adapter');
}
parent::init();
// @codeCoverageIgnoreEnd
}
/** /**
* Create http request options from request. * Create http request options from request.
* *
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
*
* @return array * @return array
*/ */
protected function createOptions($request, $endpoint) protected function createOptions($request, $endpoint)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$options = array( $options = array(
'timeout' => $endpoint->getTimeout() 'timeout' => $endpoint->getTimeout(),
); );
foreach ($request->getHeaders() as $headerLine) { foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine); list($header, $value) = explode(':', $headerLine);
...@@ -226,22 +252,4 @@ class Curl extends Configurable implements AdapterInterface ...@@ -226,22 +252,4 @@ class Curl extends Configurable implements AdapterInterface
return $options; return $options;
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/**
* Check result of a request
*
* @throws HttpException
* @param string $data
* @param array $headers
* @param resource $handle
* @return void
*/
public function check($data, $headers, $handle)
{
// if there is no data and there are no headers it's a total failure,
// a connection to the host was impossible.
if (empty($data) && count($headers) == 0) {
throw new HttpException('HTTP request failed, '.curl_error($handle));
}
}
} }
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
...@@ -45,22 +47,24 @@ use Solarium\Core\Client\Endpoint; ...@@ -45,22 +47,24 @@ use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException; use Solarium\Exception\HttpException;
/** /**
* Basic HTTP adapter using a stream * Basic HTTP adapter using a stream.
*/ */
class Http extends Configurable implements AdapterInterface class Http extends Configurable implements AdapterInterface
{ {
/** /**
* Handle Solr communication * Handle Solr communication.
* *
* @throws HttpException * @throws HttpException
* @param Request $request *
* @param Endpoint $endpoint * @param Request $request
* @param Endpoint $endpoint
*
* @return Response * @return Response
*/ */
public function execute($request, $endpoint) public function execute($request, $endpoint)
{ {
$context = $this->createContext($request, $endpoint); $context = $this->createContext($request, $endpoint);
$uri = $endpoint->getBaseUri() . $request->getUri(); $uri = $endpoint->getBaseUri().$request->getUri();
list($data, $headers) = $this->getData($uri, $context); list($data, $headers) = $this->getData($uri, $context);
...@@ -70,12 +74,12 @@ class Http extends Configurable implements AdapterInterface ...@@ -70,12 +74,12 @@ class Http extends Configurable implements AdapterInterface
} }
/** /**
* Check result of a request * Check result of a request.
* *
* @throws HttpException * @throws HttpException
* @param string $data *
* @param array $headers * @param string $data
* @return void * @param array $headers
*/ */
public function check($data, $headers) public function check($data, $headers)
{ {
...@@ -87,10 +91,11 @@ class Http extends Configurable implements AdapterInterface ...@@ -87,10 +91,11 @@ class Http extends Configurable implements AdapterInterface
} }
/** /**
* Create a stream context for a request * Create a stream context for a request.
*
* @param Request $request
* @param Endpoint $endpoint
* *
* @param Request $request
* @param Endpoint $endpoint
* @return resource * @return resource
*/ */
public function createContext($request, $endpoint) public function createContext($request, $endpoint)
...@@ -98,9 +103,10 @@ class Http extends Configurable implements AdapterInterface ...@@ -98,9 +103,10 @@ class Http extends Configurable implements AdapterInterface
$method = $request->getMethod(); $method = $request->getMethod();
$context = stream_context_create( $context = stream_context_create(
array('http' => array( array('http' => array(
'method' => $method, 'method' => $method,
'timeout' => $endpoint->getTimeout() 'timeout' => $endpoint->getTimeout(),
)) ),
)
); );
if ($method == Request::METHOD_POST) { if ($method == Request::METHOD_POST) {
...@@ -135,7 +141,7 @@ class Http extends Configurable implements AdapterInterface ...@@ -135,7 +141,7 @@ class Http extends Configurable implements AdapterInterface
if (!empty($authData['username']) && !empty($authData['password'])) { if (!empty($authData['username']) && !empty($authData['password'])) {
$request->addHeader( $request->addHeader(
'Authorization: Basic ' . base64_encode($authData['username'] . ':' . $authData['password']) 'Authorization: Basic '.base64_encode($authData['username'].':'.$authData['password'])
); );
} }
...@@ -153,10 +159,11 @@ class Http extends Configurable implements AdapterInterface ...@@ -153,10 +159,11 @@ class Http extends Configurable implements AdapterInterface
} }
/** /**
* Execute request * Execute request.
*
* @param string $uri
* @param resource $context
* *
* @param string $uri
* @param resource $context
* @return array * @return array
*/ */
protected function getData($uri, $context) protected function getData($uri, $context)
......
...@@ -31,12 +31,14 @@ ...@@ -31,12 +31,14 @@
* *
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com> * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
...@@ -48,36 +50,20 @@ use Solarium\Exception\HttpException; ...@@ -48,36 +50,20 @@ use Solarium\Exception\HttpException;
use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\InvalidArgumentException;
/** /**
* Pecl HTTP adapter * Pecl HTTP adapter.
* *
* @author Gasol Wu <gasol.wu@gmail.com> * @author Gasol Wu <gasol.wu@gmail.com>
*/ */
class PeclHttp extends Configurable implements AdapterInterface class PeclHttp extends Configurable implements AdapterInterface
{ {
/** /**
* Initialization hook * Execute a Solr request using the Pecl Http.
* *
* Checks the availability of pecl_http * @throws HttpException
* *
* @throws RuntimeException * @param Request $request
*/ * @param Endpoint $endpoint
protected function init()
{
// @codeCoverageIgnoreStart
if (!class_exists('HttpRequest', false)) {
throw new RuntimeException('Pecl_http is not available, install it to use the PeclHttp adapter');
}
parent::init();
// @codeCoverageIgnoreEnd
}
/**
* Execute a Solr request using the Pecl Http
* *
* @throws HttpException
* @param Request $request
* @param Endpoint $endpoint
* @return Response * @return Response
*/ */
public function execute($request, $endpoint) public function execute($request, $endpoint)
...@@ -97,37 +83,7 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -97,37 +83,7 @@ class PeclHttp extends Configurable implements AdapterInterface
} }
/** /**
* Convert key/value pair header to raw header. * adapt Request to HttpRequest.
*
* <code>
* //before
* $headers['Content-Type'] = 'text/plain';
*
* ...
*
* //after
* $headers[0] = 'Content-Type: text/plain';
* </code>
*
* @param $message \HttpMessage
* @return array
*/
protected function toRawHeaders($message)
{
$headers[] = 'HTTP/' . $message->getHttpVersion()
. ' ' . $message->getResponseCode()
. ' ' . $message->getResponseStatus();
foreach ($message->getHeaders() as $header => $value) {
$headers[] = "$header: $value";
}
return $headers;
}
/**
*
* adapt Request to HttpRequest
* *
* {@link http://us.php.net/manual/en/http.constants.php * {@link http://us.php.net/manual/en/http.constants.php
* HTTP Predefined Constant} * HTTP Predefined Constant}
...@@ -136,14 +92,15 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -136,14 +92,15 @@ class PeclHttp extends Configurable implements AdapterInterface
* HttpRequest options} * HttpRequest options}
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @param Request $request *
* @param Endpoint $endpoint * @param Request $request
* @param HttpRequest * @param Endpoint $endpoint
*
* @return \HttpRequest * @return \HttpRequest
*/ */
public function toHttpRequest($request, $endpoint) public function toHttpRequest($request, $endpoint)
{ {
$url = $endpoint->getBaseUri() . $request->getUri(); $url = $endpoint->getBaseUri().$request->getUri();
$httpRequest = new \HttpRequest($url); $httpRequest = new \HttpRequest($url);
$headers = array(); $headers = array();
...@@ -161,7 +118,7 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -161,7 +118,7 @@ class PeclHttp extends Configurable implements AdapterInterface
} }
if (!empty($authData['username']) && !empty($authData['password'])) { if (!empty($authData['username']) && !empty($authData['password'])) {
$headers['Authorization'] = 'Basic ' . base64_encode($authData['username']. ':' . $authData['password']); $headers['Authorization'] = 'Basic '.base64_encode($authData['username'].':'.$authData['password']);
} }
switch ($request->getMethod()) { switch ($request->getMethod()) {
...@@ -188,7 +145,7 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -188,7 +145,7 @@ class PeclHttp extends Configurable implements AdapterInterface
break; break;
default: default:
throw new InvalidArgumentException( throw new InvalidArgumentException(
'Unsupported method: ' . $request->getMethod() 'Unsupported method: '.$request->getMethod()
); );
} }
...@@ -204,4 +161,50 @@ class PeclHttp extends Configurable implements AdapterInterface ...@@ -204,4 +161,50 @@ class PeclHttp extends Configurable implements AdapterInterface
return $httpRequest; return $httpRequest;
} }
/**
* Initialization hook.
*
* Checks the availability of pecl_http
*
* @throws RuntimeException
*/
protected function init()
{
// @codeCoverageIgnoreStart
if (!class_exists('HttpRequest', false)) {
throw new RuntimeException('Pecl_http is not available, install it to use the PeclHttp adapter');
}
parent::init();
// @codeCoverageIgnoreEnd
}
/**
* Convert key/value pair header to raw header.
*
* <code>
* //before
* $headers['Content-Type'] = 'text/plain';
*
* ...
*
* //after
* $headers[0] = 'Content-Type: text/plain';
* </code>
*
* @param $message \HttpMessage
*
* @return array
*/
protected function toRawHeaders($message)
{
$headers[] = 'HTTP/'.$message->getHttpVersion().' '.$message->getResponseCode().' '.$message->getResponseStatus();
foreach ($message->getHeaders() as $header => $value) {
$headers[] = "$header: $value";
}
return $headers;
}
} }
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
* Copyright 2012 Alexander Brausewetter. 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>
* @copyright Copyright 2012 Alexander Brausewetter <alex@helpdeskhq.com>
* @copyright Copyright 2014 Marin Purgar <marin.purgar@gmail.com.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
use Solarium\Core\Client;
use Solarium\Core\Client\Request;
use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
use Solarium\Exception\OutOfBoundsException;
/**
* Adapter that uses a ZF2 Zend\Http\Client
*
* The Zend Framework HTTP client has many great features and has lots of
* configuration options. For more info see the manual at
* {@link http://framework.zend.com/manual/en/zend.http.html}
*
* To use this adapter you need to have the Zend Framework available (autoloading)
*/
class Zend2Http extends Configurable implements AdapterInterface
{
/**
* Zend Http instance for communication with Solr
*
* @var \Zend\Http\Client
*/
protected $zendHttp;
/**
* @var int
*/
protected $timeout;
/**
* Set options
*
* Overrides any existing values.
*
* If the options array has an 'options' entry it is forwarded to the
* Zend\Http\Client. See the Zend\Http\Client docs for the many config
* options available.
*
* The $options param should be an array or an object that has a toArray
* method, like Zend_Config
*
* @param array|object $options
* @param boolean $overwrite
* @return self Provides fluent interface
*/
public function setOptions($options, $overwrite = false)
{
parent::setOptions($options, $overwrite);
// forward options to zendHttp instance
if (null !== $this->zendHttp) {
// forward timeout setting
$adapterOptions = array();
// forward adapter options if available
if (isset($this->options['options'])) {
$adapterOptions = array_merge($adapterOptions, $this->options['options']);
}
$this->zendHttp->setOptions($adapterOptions);
}
return $this;
}
/**
* Set the Zend\Http\Client instance
*
* This method is optional, if you don't set a client it will be created
* upon first use, using default and/or custom options (the most common use
* case)
*
* @param \Zend\Http\Client $zendHttp
* @return self Provides fluent interface
*/
public function setZendHttp($zendHttp)
{
$this->zendHttp = $zendHttp;
return $this;
}
/**
* Get the Zend\Http\Client instance
*
* If no instance is available yet it will be created automatically based on
* options.
*
* You can use this method to get a reference to the client instance to set
* options, get the last response and use many other features offered by the
* Zend\Http\Client API.
*
* @return \Zend\Http\Client
*/
public function getZendHttp()
{
if (null == $this->zendHttp) {
$options = array();
// forward zendhttp options
if (isset($this->options['options'])) {
$options = array_merge(
$options,
$this->options['options']
);
}
$this->zendHttp = new \Zend\Http\Client(null, $options);
}
return $this->zendHttp;
}
/**
* Execute a Solr request using the Zend\Http\Client instance
*
* @throws HttpException
* @throws OutOfBoundsException
* @param Request $request
* @param Endpoint $endpoint
* @return Response
*/
public function execute($request, $endpoint)
{
$client = $this->getZendHttp();
$client->resetParameters();
switch ($request->getMethod()) {
case Request::METHOD_GET:
$client->setMethod('GET');
$client->setParameterGet($request->getParams());
break;
case Request::METHOD_POST:
$client->setMethod('POST');
if ($request->getFileUpload()) {
$this->prepareFileUpload($client, $request);
} else {
$client->setParameterGet($request->getParams());
$client->setRawBody($request->getRawData());
$request->addHeader('Content-Type: text/xml; charset=UTF-8');
}
break;
case Request::METHOD_HEAD:
$client->setMethod('HEAD');
$client->setParameterGet($request->getParams());
break;
default:
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod());
break;
}
$client->setUri($endpoint->getBaseUri() . $request->getHandler());
$client->setHeaders($request->getHeaders());
$this->timeout = $endpoint->getTimeout();
$response = $client->send();
return $this->prepareResponse(
$request,
$response
);
}
/**
* Prepare a solarium response from the given request and client
* response
*
* @throws HttpException
* @param Request $request
* @param \Zend\Http\Response $response
* @return Response
*/
protected function prepareResponse($request, $response)
{
if ($response->isClientError()) {
throw new HttpException(
$response->getReasonPhrase(),
$response->getStatusCode()
);
}
if ($request->getMethod() == Request::METHOD_HEAD) {
$data = '';
} else {
$data = $response->getBody();
}
// this is used because in ZF2 status line isn't in the headers anymore
$headers = array($response->renderStatusLine());
return new Response($data, $headers);
}
/**
* Prepare the client to send the file and params in request
*
* @param \Zend\Http\Client $client
* @param Request $request
* @return void
*/
protected function prepareFileUpload($client, $request)
{
$filename = $request->getFileUpload();
$client->setFileUpload(
'content',
'content',
file_get_contents($filename),
'application/octet-stream; charset=binary'
);
}
}
...@@ -32,12 +32,14 @@ ...@@ -32,12 +32,14 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @copyright Copyright 2012 Alexander Brausewetter <alex@helpdeskhq.com> * @copyright Copyright 2012 Alexander Brausewetter <alex@helpdeskhq.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client\Adapter; namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
...@@ -49,7 +51,7 @@ use Solarium\Exception\HttpException; ...@@ -49,7 +51,7 @@ use Solarium\Exception\HttpException;
use Solarium\Exception\OutOfBoundsException; use Solarium\Exception\OutOfBoundsException;
/** /**
* Adapter that uses a Zend_Http_Client * Adapter that uses a Zend_Http_Client.
* *
* The Zend Framework HTTP client has many great features and has lots of * The Zend Framework HTTP client has many great features and has lots of
* configuration options. For more info see the manual at * configuration options. For more info see the manual at
...@@ -60,7 +62,7 @@ use Solarium\Exception\OutOfBoundsException; ...@@ -60,7 +62,7 @@ use Solarium\Exception\OutOfBoundsException;
class ZendHttp extends Configurable implements AdapterInterface class ZendHttp extends Configurable implements AdapterInterface
{ {
/** /**
* Zend Http instance for communication with Solr * Zend Http instance for communication with Solr.
* *
* @var \Zend_Http_Client * @var \Zend_Http_Client
*/ */
...@@ -72,7 +74,7 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -72,7 +74,7 @@ class ZendHttp extends Configurable implements AdapterInterface
protected $timeout; protected $timeout;
/** /**
* Set options * Set options.
* *
* Overrides any existing values. * Overrides any existing values.
* *
...@@ -83,9 +85,10 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -83,9 +85,10 @@ class ZendHttp extends Configurable implements AdapterInterface
* The $options param should be an array or an object that has a toArray * The $options param should be an array or an object that has a toArray
* method, like Zend_Config * method, like Zend_Config
* *
* @param array|object $options * @param array|object $options
* @param boolean $overwrite * @param boolean $overwrite
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setOptions($options, $overwrite = false) public function setOptions($options, $overwrite = false)
{ {
...@@ -93,7 +96,6 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -93,7 +96,6 @@ class ZendHttp extends Configurable implements AdapterInterface
// forward options to zendHttp instance // forward options to zendHttp instance
if (null !== $this->zendHttp) { if (null !== $this->zendHttp) {
// forward timeout setting // forward timeout setting
$adapterOptions = array(); $adapterOptions = array();
...@@ -109,14 +111,15 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -109,14 +111,15 @@ class ZendHttp extends Configurable implements AdapterInterface
} }
/** /**
* Set the Zend_Http_Client instance * Set the Zend_Http_Client instance.
* *
* This method is optional, if you don't set a client it will be created * This method is optional, if you don't set a client it will be created
* upon first use, using default and/or custom options (the most common use * upon first use, using default and/or custom options (the most common use
* case) * case)
* *
* @param \Zend_Http_Client $zendHttp * @param \Zend_Http_Client $zendHttp
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setZendHttp($zendHttp) public function setZendHttp($zendHttp)
{ {
...@@ -126,7 +129,7 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -126,7 +129,7 @@ class ZendHttp extends Configurable implements AdapterInterface
} }
/** /**
* Get the Zend_Http_Client instance * Get the Zend_Http_Client instance.
* *
* If no instance is available yet it will be created automatically based on * If no instance is available yet it will be created automatically based on
* options. * options.
...@@ -157,12 +160,14 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -157,12 +160,14 @@ class ZendHttp extends Configurable implements AdapterInterface
} }
/** /**
* Execute a Solr request using the Zend_Http_Client instance * Execute a Solr request using the Zend_Http_Client instance.
* *
* @throws HttpException * @throws HttpException
* @throws OutOfBoundsException * @throws OutOfBoundsException
* @param Request $request *
* @param Endpoint $endpoint * @param Request $request
* @param Endpoint $endpoint
*
* @return Response * @return Response
*/ */
public function execute($request, $endpoint) public function execute($request, $endpoint)
...@@ -190,11 +195,11 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -190,11 +195,11 @@ class ZendHttp extends Configurable implements AdapterInterface
$client->setParameterGet($request->getParams()); $client->setParameterGet($request->getParams());
break; break;
default: default:
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod()); throw new OutOfBoundsException('Unsupported method: '.$request->getMethod());
break; break;
} }
$client->setUri($endpoint->getBaseUri() . $request->getHandler()); $client->setUri($endpoint->getBaseUri().$request->getHandler());
$client->setHeaders($request->getHeaders()); $client->setHeaders($request->getHeaders());
$this->timeout = $endpoint->getTimeout(); $this->timeout = $endpoint->getTimeout();
...@@ -208,11 +213,13 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -208,11 +213,13 @@ class ZendHttp extends Configurable implements AdapterInterface
/** /**
* Prepare a solarium response from the given request and client * Prepare a solarium response from the given request and client
* response * response.
* *
* @throws HttpException * @throws HttpException
* @param Request $request *
* @param \Zend_Http_Response $response * @param Request $request
* @param \Zend_Http_Response $response
*
* @return Response * @return Response
*/ */
protected function prepareResponse($request, $response) protected function prepareResponse($request, $response)
...@@ -237,11 +244,10 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -237,11 +244,10 @@ class ZendHttp extends Configurable implements AdapterInterface
} }
/** /**
* Prepare the client to send the file and params in request * Prepare the client to send the file and params in request.
* *
* @param \Zend_Http_Client $client * @param \Zend_Http_Client $client
* @param Request $request * @param Request $request
* @return void
*/ */
protected function prepareFileUpload($client, $request) protected function prepareFileUpload($client, $request)
{ {
......
This diff is collapsed.
...@@ -30,23 +30,25 @@ ...@@ -30,23 +30,25 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client; namespace Solarium\Core\Client;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
/** /**
* Class for describing an endpoint * Class for describing an endpoint.
*/ */
class Endpoint extends Configurable class Endpoint extends Configurable
{ {
/** /**
* Default options * Default options.
* *
* The defaults match a standard Solr example instance as distributed by * The defaults match a standard Solr example instance as distributed by
* the Apache Lucene Solr project. * the Apache Lucene Solr project.
...@@ -63,24 +65,7 @@ class Endpoint extends Configurable ...@@ -63,24 +65,7 @@ class Endpoint extends Configurable
); );
/** /**
* Initialization hook * Get key value.
*
* In this case the path needs to be cleaned of trailing slashes.
* @see setPath()
*/
protected function init()
{
foreach ($this->options as $name => $value) {
switch ($name) {
case 'path':
$this->setPath($value);
break;
}
}
}
/**
* Get key value
* *
* @return string * @return string
*/ */
...@@ -90,10 +75,11 @@ class Endpoint extends Configurable ...@@ -90,10 +75,11 @@ class Endpoint extends Configurable
} }
/** /**
* Set key value * Set key value.
* *
* @param string $value * @param string $value
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setKey($value) public function setKey($value)
{ {
...@@ -101,10 +87,11 @@ class Endpoint extends Configurable ...@@ -101,10 +87,11 @@ class Endpoint extends Configurable
} }
/** /**
* Set host option * Set host option.
*
* @param string $host This can be a hostname or an IP address
* *
* @param string $host This can be a hostname or an IP address * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setHost($host) public function setHost($host)
{ {
...@@ -112,7 +99,7 @@ class Endpoint extends Configurable ...@@ -112,7 +99,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get host option * Get host option.
* *
* @return string * @return string
*/ */
...@@ -122,9 +109,10 @@ class Endpoint extends Configurable ...@@ -122,9 +109,10 @@ class Endpoint extends Configurable
} }
/** /**
* Set port option * Set port option.
*
* @param int $port Common values are 80, 8080 and 8983
* *
* @param int $port Common values are 80, 8080 and 8983
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setPort($port) public function setPort($port)
...@@ -133,7 +121,7 @@ class Endpoint extends Configurable ...@@ -133,7 +121,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get port option * Get port option.
* *
* @return int * @return int
*/ */
...@@ -143,12 +131,13 @@ class Endpoint extends Configurable ...@@ -143,12 +131,13 @@ class Endpoint extends Configurable
} }
/** /**
* Set path option * Set path option.
* *
* If the path has a trailing slash it will be removed. * If the path has a trailing slash it will be removed.
* *
* @param string $path * @param string $path
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setPath($path) public function setPath($path)
{ {
...@@ -160,7 +149,7 @@ class Endpoint extends Configurable ...@@ -160,7 +149,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get path option * Get path option.
* *
* @return string * @return string
*/ */
...@@ -170,10 +159,11 @@ class Endpoint extends Configurable ...@@ -170,10 +159,11 @@ class Endpoint extends Configurable
} }
/** /**
* Set core option * Set core option.
*
* @param string $core
* *
* @param string $core * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setCore($core) public function setCore($core)
{ {
...@@ -181,7 +171,7 @@ class Endpoint extends Configurable ...@@ -181,7 +171,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get core option * Get core option.
* *
* @return string * @return string
*/ */
...@@ -191,9 +181,10 @@ class Endpoint extends Configurable ...@@ -191,9 +181,10 @@ class Endpoint extends Configurable
} }
/** /**
* Set timeout option * Set timeout option.
*
* @param int $timeout
* *
* @param int $timeout
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setTimeout($timeout) public function setTimeout($timeout)
...@@ -202,7 +193,7 @@ class Endpoint extends Configurable ...@@ -202,7 +193,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get timeout option * Get timeout option.
* *
* @return string * @return string
*/ */
...@@ -212,9 +203,10 @@ class Endpoint extends Configurable ...@@ -212,9 +203,10 @@ class Endpoint extends Configurable
} }
/** /**
* Set scheme option * Set scheme option.
*
* @param string $scheme
* *
* @param string $scheme
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setScheme($scheme) public function setScheme($scheme)
...@@ -223,7 +215,7 @@ class Endpoint extends Configurable ...@@ -223,7 +215,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get scheme option * Get scheme option.
* *
* @return string * @return string
*/ */
...@@ -233,7 +225,7 @@ class Endpoint extends Configurable ...@@ -233,7 +225,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get the base url for all requests * Get the base url for all requests.
* *
* Based on host, path, port and core options. * Based on host, path, port and core options.
* *
...@@ -241,7 +233,7 @@ class Endpoint extends Configurable ...@@ -241,7 +233,7 @@ class Endpoint extends Configurable
*/ */
public function getBaseUri() public function getBaseUri()
{ {
$uri = $this->getScheme() . '://' . $this->getHost() . ':' . $this->getPort() . $this->getPath() . '/'; $uri = $this->getScheme().'://'.$this->getHost().':'.$this->getPort().$this->getPath().'/';
$core = $this->getCore(); $core = $this->getCore();
if (!empty($core)) { if (!empty($core)) {
...@@ -252,13 +244,14 @@ class Endpoint extends Configurable ...@@ -252,13 +244,14 @@ class Endpoint extends Configurable
} }
/** /**
* Set HTTP basic auth settings * Set HTTP basic auth settings.
* *
* If one or both values are NULL authentication will be disabled * If one or both values are NULL authentication will be disabled
* *
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setAuthentication($username, $password) public function setAuthentication($username, $password)
{ {
...@@ -269,7 +262,7 @@ class Endpoint extends Configurable ...@@ -269,7 +262,7 @@ class Endpoint extends Configurable
} }
/** /**
* Get HTTP basic auth settings * Get HTTP basic auth settings.
* *
* @return array * @return array
*/ */
...@@ -282,7 +275,7 @@ class Endpoint extends Configurable ...@@ -282,7 +275,7 @@ class Endpoint extends Configurable
} }
/** /**
* Magic method enables a object to be transformed to a string * Magic method enables a object to be transformed to a string.
* *
* Get a summary showing significant variables in the object * Get a summary showing significant variables in the object
* note: uri resource is decoded for readability * note: uri resource is decoded for readability
...@@ -291,15 +284,26 @@ class Endpoint extends Configurable ...@@ -291,15 +284,26 @@ class Endpoint extends Configurable
*/ */
public function __toString() public function __toString()
{ {
$output = __CLASS__ . '::__toString' . "\n" $output = __CLASS__.'::__toString'."\n".'base uri: '.$this->getBaseUri()."\n".'host: '.$this->getHost()."\n".'port: '.$this->getPort()."\n".'path: '.$this->getPath()."\n".'core: '.$this->getCore()."\n".'timeout: '.$this->getTimeout()."\n".'authentication: '.print_r($this->getAuthentication(), 1);
. 'base uri: ' . $this->getBaseUri() . "\n"
. 'host: ' . $this->getHost() . "\n"
. 'port: ' . $this->getPort() ."\n"
. 'path: ' . $this->getPath() ."\n"
. 'core: ' . $this->getCore() . "\n"
. 'timeout: ' . $this->getTimeout() . "\n"
. 'authentication: ' . print_r($this->getAuthentication(), 1);
return $output; return $output;
} }
/**
* Initialization hook.
*
* In this case the path needs to be cleaned of trailing slashes.
*
* @see setPath()
*/
protected function init()
{
foreach ($this->options as $name => $value) {
switch ($name) {
case 'path':
$this->setPath($value);
break;
}
}
}
} }
This diff is collapsed.
...@@ -30,51 +30,53 @@ ...@@ -30,51 +30,53 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Client; namespace Solarium\Core\Client;
use Solarium\Exception\HttpException; use Solarium\Exception\HttpException;
/** /**
* Class for describing a response * Class for describing a response.
*/ */
class Response class Response
{ {
/** /**
* Headers * Headers.
* *
* @var array * @var array
*/ */
protected $headers; protected $headers;
/** /**
* Body * Body.
* *
* @var string * @var string
*/ */
protected $body; protected $body;
/** /**
* HTTP response code * HTTP response code.
* *
* @var int * @var int
*/ */
protected $statusCode; protected $statusCode;
/** /**
* HTTP response message * HTTP response message.
* *
* @var string * @var string
*/ */
protected $statusMessage; protected $statusMessage;
/** /**
* Constructor * Constructor.
* *
* @param string $body * @param string $body
* @param array $headers * @param array $headers
...@@ -88,7 +90,7 @@ class Response ...@@ -88,7 +90,7 @@ class Response
} }
/** /**
* Get body data * Get body data.
* *
* @return string * @return string
*/ */
...@@ -98,7 +100,7 @@ class Response ...@@ -98,7 +100,7 @@ class Response
} }
/** /**
* Get response headers * Get response headers.
* *
* @return array * @return array
*/ */
...@@ -108,7 +110,7 @@ class Response ...@@ -108,7 +110,7 @@ class Response
} }
/** /**
* Get status code * Get status code.
* *
* @return int * @return int
*/ */
...@@ -118,7 +120,7 @@ class Response ...@@ -118,7 +120,7 @@ class Response
} }
/** /**
* Get status message * Get status message.
* *
* @return string * @return string
*/ */
...@@ -128,11 +130,11 @@ class Response ...@@ -128,11 +130,11 @@ class Response
} }
/** /**
* Set headers * Set headers.
* *
* @throws HttpException * @throws HttpException
* @param array $headers *
* @return void * @param array $headers
*/ */
public function setHeaders($headers) public function setHeaders($headers)
{ {
......
...@@ -30,18 +30,20 @@ ...@@ -30,18 +30,20 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core; namespace Solarium\Core;
use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\InvalidArgumentException;
/** /**
* Base class for configurable classes * Base class for configurable classes.
* *
* All classes extending this class are configurable using the constructor or * All classes extending this class are configurable using the constructor or
* setOption calls. This is the base for many Solarium classes, providing a * setOption calls. This is the base for many Solarium classes, providing a
...@@ -50,15 +52,14 @@ use Solarium\Exception\InvalidArgumentException; ...@@ -50,15 +52,14 @@ use Solarium\Exception\InvalidArgumentException;
class Configurable implements ConfigurableInterface class Configurable implements ConfigurableInterface
{ {
/** /**
* Default options * Default options.
* *
* @var array * @var array
*/ */
protected $options = array( protected $options = array();
);
/** /**
* Constructor * Constructor.
* *
* If options are passed they will be merged with {@link $options} using * If options are passed they will be merged with {@link $options} using
* the {@link setOptions()} method. * the {@link setOptions()} method.
...@@ -66,7 +67,8 @@ class Configurable implements ConfigurableInterface ...@@ -66,7 +67,8 @@ class Configurable implements ConfigurableInterface
* After handling the options the {@link _init()} method is called. * After handling the options the {@link _init()} method is called.
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @param array|\Zend_Config $options *
* @param array|\Zend_Config $options
*/ */
public function __construct($options = null) public function __construct($options = null)
{ {
...@@ -78,7 +80,7 @@ class Configurable implements ConfigurableInterface ...@@ -78,7 +80,7 @@ class Configurable implements ConfigurableInterface
} }
/** /**
* Set options * Set options.
* *
* If $options is an object, it will be converted into an array by calling * If $options is an object, it will be converted into an array by calling
* its toArray method. This is compatible with the Zend_Config classes in * its toArray method. This is compatible with the Zend_Config classes in
...@@ -87,11 +89,10 @@ class Configurable implements ConfigurableInterface ...@@ -87,11 +89,10 @@ class Configurable implements ConfigurableInterface
* be used instead. * be used instead.
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @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 * @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*/ */
public function setOptions($options, $overwrite = false) public function setOptions($options, $overwrite = false)
{ {
...@@ -119,77 +120,76 @@ class Configurable implements ConfigurableInterface ...@@ -119,77 +120,76 @@ class Configurable implements ConfigurableInterface
} }
/** /**
* Initialization hook * Get an option value by name.
*
* Can be used by classes for special behaviour. For instance some options
* have extra setup work in their 'set' method that also need to be called
* when the option is passed as a constructor argument.
* *
* This hook is called by the constructor after saving the constructor * If the option is empty or not set a NULL value will be returned.
* arguments in {@link $options}
* *
* @internal This empty implementation can optionally be implemented in * @param string $name
* descending classes. It's not an abstract method on purpose, there are
* many cases where no initialization is needed.
* *
* @return void * @return mixed
*/ */
protected function init() public function getOption($name)
{ {
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return;
}
} }
/** /**
* Set an option * Get all options.
* *
* @param string $name * @return array
* @param mixed $value
* @return self Provides fluent interface
*/ */
protected function setOption($name, $value) public function getOptions()
{ {
$this->options[$name] = $value; return $this->options;
return $this;
} }
/** /**
* Get an option value by name * Initialization hook.
* *
* If the option is empty or not set a NULL value will be returned. * Can be used by classes for special behaviour. For instance some options
* have extra setup work in their 'set' method that also need to be called
* when the option is passed as a constructor argument.
* *
* @param string $name * This hook is called by the constructor after saving the constructor
* @return mixed * arguments in {@link $options}
*
* @internal This empty implementation can optionally be implemented in
* descending classes. It's not an abstract method on purpose, there are
* many cases where no initialization is needed.
*/ */
public function getOption($name) protected function init()
{ {
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return null;
}
} }
/** /**
* Get all options * Set an option.
* *
* @return array * @param string $name
* @param mixed $value
*
* @return self Provides fluent interface
*/ */
public function getOptions() protected function setOption($name, $value)
{ {
return $this->options; $this->options[$name] = $value;
return $this;
} }
/** /**
* Turns an object array into an associative multidimensional array. * Turns an object array into an associative multidimensional array.
* *
* @param $object * @param $object
*
* @return array|object * @return array|object
*/ */
protected function toArray($object) protected function toArray($object)
{ {
if (is_object($object)) if (is_object($object)) {
{
// get_object_vars() does not handle recursive objects well, // get_object_vars() does not handle recursive objects well,
// so use set-type without scope operator instead // so use set-type without scope operator instead
settype($object, 'array'); settype($object, 'array');
...@@ -200,7 +200,9 @@ class Configurable implements ConfigurableInterface ...@@ -200,7 +200,9 @@ class Configurable implements ConfigurableInterface
* Using __METHOD__ (Magic constant) * Using __METHOD__ (Magic constant)
* for recursive call * for recursive call
*/ */
if (is_array($object)) return array_map(__METHOD__, $object); if (is_array($object)) {
return array_map(__METHOD__, $object);
}
return $object; return $object;
} }
......
...@@ -30,18 +30,20 @@ ...@@ -30,18 +30,20 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core; namespace Solarium\Core;
use Solarium\Exception\InvalidArgumentException; use Solarium\Exception\InvalidArgumentException;
/** /**
* Interface for configurable classes * Interface for configurable classes.
* *
* All classes implementing this interface are configurable using the constructor or * All classes implementing this interface are configurable using the constructor or
* setOption calls. This is the base for many Solarium classes, providing a * setOption calls. This is the base for many Solarium classes, providing a
...@@ -49,35 +51,34 @@ use Solarium\Exception\InvalidArgumentException; ...@@ -49,35 +51,34 @@ use Solarium\Exception\InvalidArgumentException;
*/ */
interface ConfigurableInterface interface ConfigurableInterface
{ {
/** /**
* Set options * Set options.
* *
* If $options is an object it will be converted into an array by called * 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 * 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. * Zend Framework, but can also easily be implemented in any other object.
* *
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @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 * @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*/ */
public function setOptions($options, $overwrite = false); public function setOptions($options, $overwrite = false);
/** /**
* Get an option value by name * Get an option value by name.
* *
* If the option is empty or not set a NULL value will be returned. * If the option is empty or not set a NULL value will be returned.
* *
* @param string $name * @param string $name
*
* @return mixed * @return mixed
*/ */
public function getOption($name); public function getOption($name);
/** /**
* Get all options * Get all options.
* *
* @return array * @return array
*/ */
......
...@@ -30,16 +30,18 @@ ...@@ -30,16 +30,18 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
/** /**
* Event definitions * Event definitions.
*/ */
class Events class Events
{ {
...@@ -64,7 +66,7 @@ class Events ...@@ -64,7 +66,7 @@ class Events
const POST_CREATE_REQUEST = 'solarium.core.postCreateRequest'; const POST_CREATE_REQUEST = 'solarium.core.postCreateRequest';
/** /**
* The preExecuteRequest event is thrown just before a request is sent to Solr * The preExecuteRequest event is thrown just before a request is sent to Solr.
* *
* The event listener receives a Request instance. * The event listener receives a Request instance.
* *
...@@ -82,7 +84,7 @@ class Events ...@@ -82,7 +84,7 @@ class Events
const POST_EXECUTE_REQUEST = 'solarium.core.postExecuteRequest'; const POST_EXECUTE_REQUEST = 'solarium.core.postExecuteRequest';
/** /**
* The preCreateResult event is before the Solr response data is parsed into a result object * The preCreateResult event is before the Solr response data is parsed into a result object.
* *
* The event listener receives a Query and a Response instance. * The event listener receives a Query and a Response instance.
* *
...@@ -91,7 +93,7 @@ class Events ...@@ -91,7 +93,7 @@ class Events
const PRE_CREATE_RESULT = 'solarium.core.preCreateResult'; const PRE_CREATE_RESULT = 'solarium.core.preCreateResult';
/** /**
* The postCreateResult event is thrown just after the Solr response data was parsed into a result object * The postCreateResult event is thrown just after the Solr response data was parsed into a result object.
* *
* The event listener receives a Query, Response and Result instance. * The event listener receives a Query, Response and Result instance.
* *
......
...@@ -30,19 +30,21 @@ ...@@ -30,19 +30,21 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Solarium\Core\Query\QueryInterface; use Solarium\Core\Query\QueryInterface;
/** /**
* PostCreateQuery event, see Events for details * PostCreateQuery event, see Events for details.
*/ */
class PostCreateQuery extends Event class PostCreateQuery extends Event
{ {
...@@ -62,7 +64,7 @@ class PostCreateQuery extends Event ...@@ -62,7 +64,7 @@ class PostCreateQuery extends Event
protected $options; protected $options;
/** /**
* Event constructor * Event constructor.
* *
* @param string $type * @param string $type
* @param array $options * @param array $options
...@@ -76,7 +78,7 @@ class PostCreateQuery extends Event ...@@ -76,7 +78,7 @@ class PostCreateQuery extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -86,7 +88,7 @@ class PostCreateQuery extends Event ...@@ -86,7 +88,7 @@ class PostCreateQuery extends Event
} }
/** /**
* Get the querytype for this event * Get the querytype for this event.
* *
* @return string * @return string
*/ */
...@@ -96,7 +98,7 @@ class PostCreateQuery extends Event ...@@ -96,7 +98,7 @@ class PostCreateQuery extends Event
} }
/** /**
* Get the options for this event * Get the options for this event.
* *
* @return string * @return string
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface; ...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
/** /**
* PostCreateRequest event, see Events for details * PostCreateRequest event, see Events for details.
*/ */
class PostCreateRequest extends Event class PostCreateRequest extends Event
{ {
...@@ -58,7 +60,7 @@ class PostCreateRequest extends Event ...@@ -58,7 +60,7 @@ class PostCreateRequest extends Event
protected $request; protected $request;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
* @param Request $request * @param Request $request
...@@ -70,7 +72,7 @@ class PostCreateRequest extends Event ...@@ -70,7 +72,7 @@ class PostCreateRequest extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -80,7 +82,7 @@ class PostCreateRequest extends Event ...@@ -80,7 +82,7 @@ class PostCreateRequest extends Event
} }
/** /**
* Get the request object for this event * Get the request object for this event.
* *
* @return Request * @return Request
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response; ...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\ResultInterface; use Solarium\Core\Query\Result\ResultInterface;
/** /**
* PostCreateResult event, see Events for details * PostCreateResult event, see Events for details.
*/ */
class PostCreateResult extends Event class PostCreateResult extends Event
{ {
...@@ -64,7 +66,7 @@ class PostCreateResult extends Event ...@@ -64,7 +66,7 @@ class PostCreateResult extends Event
protected $result; protected $result;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
* @param Response $response * @param Response $response
...@@ -78,7 +80,7 @@ class PostCreateResult extends Event ...@@ -78,7 +80,7 @@ class PostCreateResult extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -88,7 +90,7 @@ class PostCreateResult extends Event ...@@ -88,7 +90,7 @@ class PostCreateResult extends Event
} }
/** /**
* Get the response object for this event * Get the response object for this event.
* *
* @return Response * @return Response
*/ */
...@@ -98,7 +100,7 @@ class PostCreateResult extends Event ...@@ -98,7 +100,7 @@ class PostCreateResult extends Event
} }
/** /**
* Get the result object for this event * Get the result object for this event.
* *
* @return ResultInterface * @return ResultInterface
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface; ...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result\ResultInterface; use Solarium\Core\Query\Result\ResultInterface;
/** /**
* PostExecute event, see Events for details * PostExecute event, see Events for details.
*/ */
class PostExecute extends Event class PostExecute extends Event
{ {
...@@ -58,7 +60,7 @@ class PostExecute extends Event ...@@ -58,7 +60,7 @@ class PostExecute extends Event
protected $result; protected $result;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
* @param ResultInterface $result * @param ResultInterface $result
...@@ -70,7 +72,7 @@ class PostExecute extends Event ...@@ -70,7 +72,7 @@ class PostExecute extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -80,7 +82,7 @@ class PostExecute extends Event ...@@ -80,7 +82,7 @@ class PostExecute extends Event
} }
/** /**
* Get the result object for this event * Get the result object for this event.
* *
* @return ResultInterface * @return ResultInterface
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response; ...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Endpoint;
/** /**
* PostExecuteRequest event, see Events for details * PostExecuteRequest event, see Events for details.
*/ */
class PostExecuteRequest extends Event class PostExecuteRequest extends Event
{ {
...@@ -54,17 +56,17 @@ class PostExecuteRequest extends Event ...@@ -54,17 +56,17 @@ class PostExecuteRequest extends Event
protected $request; protected $request;
/** /**
* @var Endpoint * @var Endpoint
*/ */
protected $endpoint; protected $endpoint;
/** /**
* @var Response * @var Response
*/ */
protected $response; protected $response;
/** /**
* Event constructor * Event constructor.
* *
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
...@@ -78,7 +80,7 @@ class PostExecuteRequest extends Event ...@@ -78,7 +80,7 @@ class PostExecuteRequest extends Event
} }
/** /**
* Get the endpoint object for this event * Get the endpoint object for this event.
* *
* @return Endpoint * @return Endpoint
*/ */
...@@ -88,7 +90,7 @@ class PostExecuteRequest extends Event ...@@ -88,7 +90,7 @@ class PostExecuteRequest extends Event
} }
/** /**
* Get the response object for this event * Get the response object for this event.
* *
* @return Response * @return Response
*/ */
...@@ -98,7 +100,7 @@ class PostExecuteRequest extends Event ...@@ -98,7 +100,7 @@ class PostExecuteRequest extends Event
} }
/** /**
* Get the request object for this event * Get the request object for this event.
* *
* @return Request * @return Request
*/ */
......
...@@ -30,19 +30,21 @@ ...@@ -30,19 +30,21 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Solarium\Core\Query\QueryInterface; use Solarium\Core\Query\QueryInterface;
/** /**
* PreCreateQuery event, see Events for details * PreCreateQuery event, see Events for details.
*/ */
class PreCreateQuery extends Event class PreCreateQuery extends Event
{ {
...@@ -62,7 +64,7 @@ class PreCreateQuery extends Event ...@@ -62,7 +64,7 @@ class PreCreateQuery extends Event
protected $options; protected $options;
/** /**
* Event constructor * Event constructor.
* *
* @param string $type * @param string $type
* @param array|null $options * @param array|null $options
...@@ -74,7 +76,7 @@ class PreCreateQuery extends Event ...@@ -74,7 +76,7 @@ class PreCreateQuery extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -84,10 +86,9 @@ class PreCreateQuery extends Event ...@@ -84,10 +86,9 @@ class PreCreateQuery extends Event
} }
/** /**
* Set the query object for this event, this overrides default execution * Set the query object for this event, this overrides default execution.
* *
* @param QueryInterface $query * @param QueryInterface $query
* @return void
*/ */
public function setQuery($query) public function setQuery($query)
{ {
...@@ -95,7 +96,7 @@ class PreCreateQuery extends Event ...@@ -95,7 +96,7 @@ class PreCreateQuery extends Event
} }
/** /**
* Get the querytype for this event * Get the querytype for this event.
* *
* @return string * @return string
*/ */
...@@ -105,7 +106,7 @@ class PreCreateQuery extends Event ...@@ -105,7 +106,7 @@ class PreCreateQuery extends Event
} }
/** /**
* Get the options for this event * Get the options for this event.
* *
* @return array|null * @return array|null
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface; ...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
/** /**
* PreCreateRequest event, see Events for details * PreCreateRequest event, see Events for details.
*/ */
class PreCreateRequest extends Event class PreCreateRequest extends Event
{ {
...@@ -58,7 +60,7 @@ class PreCreateRequest extends Event ...@@ -58,7 +60,7 @@ class PreCreateRequest extends Event
protected $request; protected $request;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
*/ */
...@@ -68,7 +70,7 @@ class PreCreateRequest extends Event ...@@ -68,7 +70,7 @@ class PreCreateRequest extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -78,12 +80,11 @@ class PreCreateRequest extends Event ...@@ -78,12 +80,11 @@ class PreCreateRequest extends Event
} }
/** /**
* Set request * Set request.
* *
* If you set this request value the default execution is skipped and this request is directly returned * If you set this request value the default execution is skipped and this request is directly returned
* *
* @param Request $request * @param Request $request
* @return void
*/ */
public function setRequest(Request $request) public function setRequest(Request $request)
{ {
...@@ -91,7 +92,7 @@ class PreCreateRequest extends Event ...@@ -91,7 +92,7 @@ class PreCreateRequest extends Event
} }
/** /**
* Get the result * Get the result.
* *
* @return null|Request * @return null|Request
*/ */
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response; ...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\ResultInterface; use Solarium\Core\Query\Result\ResultInterface;
/** /**
* PreCreateResult event, see Events for details * PreCreateResult event, see Events for details.
*/ */
class PreCreateResult extends Event class PreCreateResult extends Event
{ {
...@@ -64,7 +66,7 @@ class PreCreateResult extends Event ...@@ -64,7 +66,7 @@ class PreCreateResult extends Event
protected $result; protected $result;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
* @param Response $response * @param Response $response
...@@ -76,7 +78,7 @@ class PreCreateResult extends Event ...@@ -76,7 +78,7 @@ class PreCreateResult extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -86,7 +88,7 @@ class PreCreateResult extends Event ...@@ -86,7 +88,7 @@ class PreCreateResult extends Event
} }
/** /**
* Get the response object for this event * Get the response object for this event.
* *
* @return Response * @return Response
*/ */
...@@ -96,7 +98,7 @@ class PreCreateResult extends Event ...@@ -96,7 +98,7 @@ class PreCreateResult extends Event
} }
/** /**
* Get the result object for this event * Get the result object for this event.
* *
* @return ResultInterface * @return ResultInterface
*/ */
...@@ -106,10 +108,9 @@ class PreCreateResult extends Event ...@@ -106,10 +108,9 @@ class PreCreateResult extends Event
} }
/** /**
* Set the result object for this event, overrides default execution * Set the result object for this event, overrides default execution.
* *
* @param ResultInterface $result * @param ResultInterface $result
* @return void
*/ */
public function setResult($result) public function setResult($result)
{ {
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface; ...@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result\ResultInterface; use Solarium\Core\Query\Result\ResultInterface;
/** /**
* PostExecute event, see Events for details * PostExecute event, see Events for details.
*/ */
class PreExecute extends Event class PreExecute extends Event
{ {
...@@ -58,7 +60,7 @@ class PreExecute extends Event ...@@ -58,7 +60,7 @@ class PreExecute extends Event
protected $result; protected $result;
/** /**
* Event constructor * Event constructor.
* *
* @param QueryInterface $query * @param QueryInterface $query
*/ */
...@@ -68,7 +70,7 @@ class PreExecute extends Event ...@@ -68,7 +70,7 @@ class PreExecute extends Event
} }
/** /**
* Get the query object for this event * Get the query object for this event.
* *
* @return QueryInterface * @return QueryInterface
*/ */
...@@ -78,7 +80,7 @@ class PreExecute extends Event ...@@ -78,7 +80,7 @@ class PreExecute extends Event
} }
/** /**
* Get the result object for this event * Get the result object for this event.
* *
* @return ResultInterface * @return ResultInterface
*/ */
...@@ -88,10 +90,9 @@ class PreExecute extends Event ...@@ -88,10 +90,9 @@ class PreExecute extends Event
} }
/** /**
* Set the result object for this event, overrides default execution * Set the result object for this event, overrides default execution.
* *
* @param ResultInterface $result * @param ResultInterface $result
* @return void
*/ */
public function setResult($result) public function setResult($result)
{ {
......
...@@ -30,12 +30,14 @@ ...@@ -30,12 +30,14 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Event; namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response; ...@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint; use Solarium\Core\Client\Endpoint;
/** /**
* PreExecuteRequest event, see Events for details * PreExecuteRequest event, see Events for details.
*/ */
class PreExecuteRequest extends Event class PreExecuteRequest extends Event
{ {
...@@ -54,17 +56,17 @@ class PreExecuteRequest extends Event ...@@ -54,17 +56,17 @@ class PreExecuteRequest extends Event
protected $request; protected $request;
/** /**
* @var Endpoint * @var Endpoint
*/ */
protected $endpoint; protected $endpoint;
/** /**
* @var Response * @var Response
*/ */
protected $response; protected $response;
/** /**
* Event constructor * Event constructor.
* *
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
...@@ -76,7 +78,7 @@ class PreExecuteRequest extends Event ...@@ -76,7 +78,7 @@ class PreExecuteRequest extends Event
} }
/** /**
* Get the endpoint object for this event * Get the endpoint object for this event.
* *
* @return Endpoint * @return Endpoint
*/ */
...@@ -86,7 +88,7 @@ class PreExecuteRequest extends Event ...@@ -86,7 +88,7 @@ class PreExecuteRequest extends Event
} }
/** /**
* Get the request object for this event * Get the request object for this event.
* *
* @return Request * @return Request
*/ */
...@@ -96,10 +98,9 @@ class PreExecuteRequest extends Event ...@@ -96,10 +98,9 @@ class PreExecuteRequest extends Event
} }
/** /**
* Get the request object for this event * Get the request object for this event.
* *
* @param Request $request * @param Request $request
* @return void
*/ */
public function setRequest($request) public function setRequest($request)
{ {
...@@ -107,7 +108,7 @@ class PreExecuteRequest extends Event ...@@ -107,7 +108,7 @@ class PreExecuteRequest extends Event
} }
/** /**
* Get the response object for this event * Get the response object for this event.
* *
* @return Response * @return Response
*/ */
...@@ -117,10 +118,9 @@ class PreExecuteRequest extends Event ...@@ -117,10 +118,9 @@ class PreExecuteRequest extends Event
} }
/** /**
* Set the response object for this event, overrides default execution * Set the response object for this event, overrides default execution.
* *
* @param Response $response * @param Response $response
* @return void
*/ */
public function setResponse($response) public function setResponse($response)
{ {
......
...@@ -30,31 +30,33 @@ ...@@ -30,31 +30,33 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Plugin; namespace Solarium\Core\Plugin;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
/** /**
* Base class for plugins * Base class for plugins.
*/ */
abstract class Plugin extends Configurable implements PluginInterface abstract class AbstractPlugin extends Configurable implements PluginInterface
{ {
/** /**
* Client instance * Client instance.
* *
* @var Client * @var Client
*/ */
protected $client; protected $client;
/** /**
* Initialize * Initialize.
* *
* This method is called when the plugin is registered to a client instance * This method is called when the plugin is registered to a client instance
* *
...@@ -70,15 +72,12 @@ abstract class Plugin extends Configurable implements PluginInterface ...@@ -70,15 +72,12 @@ abstract class Plugin extends Configurable implements PluginInterface
} }
/** /**
* Plugin init function * Plugin init function.
* *
* This is an extension point for plugin implementations. * This is an extension point for plugin implementations.
* Will be called as soon as $this->client and options have been set. * Will be called as soon as $this->client and options have been set.
*
* @return void
*/ */
protected function initPluginType() protected function initPluginType()
{ {
} }
} }
...@@ -30,24 +30,26 @@ ...@@ -30,24 +30,26 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Plugin; namespace Solarium\Core\Plugin;
use Solarium\Core\ConfigurableInterface; use Solarium\Core\ConfigurableInterface;
use Solarium\Core\Client\Client; use Solarium\Core\Client\Client;
/** /**
* Interface for plugins * Interface for plugins.
*/ */
interface PluginInterface extends ConfigurableInterface interface PluginInterface extends ConfigurableInterface
{ {
/** /**
* Initialize * Initialize.
* *
* This method is called when the plugin is registered to a client instance * This method is called when the plugin is registered to a client instance
* *
......
...@@ -30,44 +30,46 @@ ...@@ -30,44 +30,46 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
use Solarium\Core\Configurable; use Solarium\Core\Configurable;
/** /**
* Base class for all query types, not intended for direct usage * Base class for all query types, not intended for direct usage.
*/ */
abstract class Query extends Configurable implements QueryInterface abstract class AbstractQuery extends Configurable implements QueryInterface
{ {
const WT_JSON = 'json'; const WT_JSON = 'json';
const WT_PHPS = 'phps'; const WT_PHPS = 'phps';
/** /**
* Helper instance * Helper instance.
* *
* @var Helper * @var Helper
*/ */
protected $helper; protected $helper;
/** /**
* Extra query params (e.g. dereferenced params) * Extra query params (e.g. dereferenced params).
* *
* @var array * @var array
*/ */
protected $params = array(); protected $params = array();
/** /**
* Set handler option * Set handler option.
*
* @param string $handler
* *
* @param string $handler * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setHandler($handler) public function setHandler($handler)
{ {
...@@ -75,7 +77,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -75,7 +77,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get handler option * Get handler option.
* *
* @return string * @return string
*/ */
...@@ -85,7 +87,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -85,7 +87,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Set resultclass option * Set resultclass option.
* *
* If you set a custom result class it must be available through autoloading * If you set a custom result class it must be available through autoloading
* or a manual require before calling this method. This is your * or a manual require before calling this method. This is your
...@@ -94,8 +96,9 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -94,8 +96,9 @@ abstract class Query extends Configurable implements QueryInterface
* Also you need to make sure it extends the orginal result class of the * Also you need to make sure it extends the orginal result class of the
* query or has an identical API. * query or has an identical API.
* *
* @param string $classname * @param string $classname
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setResultClass($classname) public function setResultClass($classname)
{ {
...@@ -103,7 +106,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -103,7 +106,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get resultclass option * Get resultclass option.
* *
* @return string * @return string
*/ */
...@@ -113,9 +116,10 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -113,9 +116,10 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Set timeAllowed option * Set timeAllowed option.
*
* @param int $value
* *
* @param int $value
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
public function setTimeAllowed($value) public function setTimeAllowed($value)
...@@ -124,7 +128,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -124,7 +128,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get timeAllowed option * Get timeAllowed option.
* *
* @return int|null * @return int|null
*/ */
...@@ -134,10 +138,11 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -134,10 +138,11 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Set omitHeader option * Set omitHeader option.
*
* @param boolean $value
* *
* @param boolean $value * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setOmitHeader($value) public function setOmitHeader($value)
{ {
...@@ -145,7 +150,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -145,7 +150,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get omitHeader option * Get omitHeader option.
* *
* @return boolean * @return boolean
*/ */
...@@ -155,7 +160,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -155,7 +160,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get a helper instance * Get a helper instance.
* *
* Uses lazy loading: the helper is instantiated on first use * Uses lazy loading: the helper is instantiated on first use
* *
...@@ -171,14 +176,15 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -171,14 +176,15 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Add extra params to the request * Add extra params to the request.
* *
* Only intended for internal use, for instance with dereferenced params. * Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get * Therefore the params are limited in functionality. Only add and get
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function addParam($name, $value) public function addParam($name, $value)
{ {
...@@ -188,7 +194,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -188,7 +194,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get extra params * Get extra params.
* *
* @return array * @return array
*/ */
...@@ -198,10 +204,11 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -198,10 +204,11 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Set responsewriter option * Set responsewriter option.
*
* @param string $value
* *
* @param string $value * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setResponseWriter($value) public function setResponseWriter($value)
{ {
...@@ -209,7 +216,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -209,7 +216,7 @@ abstract class Query extends Configurable implements QueryInterface
} }
/** /**
* Get responsewriter option * Get responsewriter option.
* *
* Defaults to json for backwards compatibility and security. * Defaults to json for backwards compatibility and security.
* *
......
...@@ -30,30 +30,33 @@ ...@@ -30,30 +30,33 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
/** /**
* Class for building Solarium client requests * Class for building Solarium client requests.
*/ */
abstract class RequestBuilder implements RequestBuilderInterface abstract class AbstractRequestBuilder implements RequestBuilderInterface
{ {
/** /**
* Build request for a select query * Build request for a select query.
*
* @param QueryInterface|Query $query
* *
* @param QueryInterface|Query $query
* @return Request * @return Request
*/ */
public function build(QueryInterface $query) public function build(QueryInterface $query)
{ {
$request = new Request; $request = new Request();
$request->setHandler($query->getHandler()); $request->setHandler($query->getHandler());
$request->addParam('omitHeader', $query->getOmitHeader()); $request->addParam('omitHeader', $query->getOmitHeader());
$request->addParam('timeAllowed', $query->getTimeAllowed()); $request->addParam('timeAllowed', $query->getTimeAllowed());
...@@ -69,13 +72,15 @@ abstract class RequestBuilder implements RequestBuilderInterface ...@@ -69,13 +72,15 @@ abstract class RequestBuilder implements RequestBuilderInterface
} }
/** /**
* Render a param with localParams * Render a param with localParams.
* *
* LocalParams can be use in various Solr GET params. * LocalParams can be use in various Solr GET params.
*
* @link http://wiki.apache.org/solr/LocalParams * @link http://wiki.apache.org/solr/LocalParams
* *
* @param string $value * @param string $value
* @param array $localParams in key => value format * @param array $localParams in key => value format
*
* @return string with Solr localparams syntax * @return string with Solr localparams syntax
*/ */
public function renderLocalParams($value, $localParams = array()) public function renderLocalParams($value, $localParams = array())
...@@ -90,25 +95,26 @@ abstract class RequestBuilder implements RequestBuilderInterface ...@@ -90,25 +95,26 @@ abstract class RequestBuilder implements RequestBuilderInterface
$paramValue = implode($paramValue, ','); $paramValue = implode($paramValue, ',');
} }
$params .= $paramName . '=' . $paramValue . ' '; $params .= $paramName.'='.$paramValue.' ';
} }
if ($params !== '') { if ($params !== '') {
$value = '{!' . trim($params) . '}' . $value; $value = '{!'.trim($params).'}'.$value;
} }
return $value; return $value;
} }
/** /**
* Render a boolean attribute * Render a boolean attribute.
* *
* For use in building XML messages * For use in building XML messages
* *
* @param string $name * @param string $name
* @param boolean $value * @param boolean $value
* @return string *
*/ * @return string
*/
public function boolAttrib($name, $value) public function boolAttrib($name, $value)
{ {
if (null !== $value) { if (null !== $value) {
...@@ -121,18 +127,19 @@ abstract class RequestBuilder implements RequestBuilderInterface ...@@ -121,18 +127,19 @@ abstract class RequestBuilder implements RequestBuilderInterface
} }
/** /**
* Render an attribute * Render an attribute.
* *
* For use in building XML messages * For use in building XML messages
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @return string *
*/ * @return string
*/
public function attrib($name, $value) public function attrib($name, $value)
{ {
if (null !== $value) { if (null !== $value) {
return ' ' . $name . '="' . $value . '"'; return ' '.$name.'="'.$value.'"';
} else { } else {
return ''; return '';
} }
......
...@@ -30,25 +30,28 @@ ...@@ -30,25 +30,28 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
/** /**
* Abstract class for response parsers * Abstract class for response parsers.
* *
* Base class with shared functionality for querytype responseparser implementations * Base class with shared functionality for querytype responseparser implementations
*/ */
abstract class ResponseParser abstract class AbstractResponseParser
{ {
/** /**
* Converts a flat key-value array (alternating rows) as used in Solr JSON results to a real key value array * Converts a flat key-value array (alternating rows) as used in Solr JSON results to a real key value array.
*
* @param array $data
* *
* @param $data
* @return array * @return array
*/ */
public function convertToKeyValueArray($data) public function convertToKeyValueArray($data)
...@@ -58,7 +61,6 @@ abstract class ResponseParser ...@@ -58,7 +61,6 @@ abstract class ResponseParser
$result = array(); $result = array();
for ($i = 0; $i < count($data); $i += 2) { for ($i = 0; $i < count($data); $i += 2) {
$key = $data[$i]; $key = $data[$i];
$value = $data[$i+1]; $value = $data[$i+1];
if (array_key_exists($key, $keys)) { if (array_key_exists($key, $keys)) {
...@@ -77,10 +79,11 @@ abstract class ResponseParser ...@@ -77,10 +79,11 @@ abstract class ResponseParser
} }
/** /**
* Parses header data (if available) and adds it to result data * Parses header data (if available) and adds it to result data.
*
* @param array $data
* @param array $result
* *
* @param array $data
* @param array $result
* @return mixed * @return mixed
*/ */
public function addHeaderInfo($data, $result) public function addHeaderInfo($data, $result)
......
This diff is collapsed.
...@@ -30,59 +30,62 @@ ...@@ -30,59 +30,62 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
use Solarium\Core\ConfigurableInterface; use Solarium\Core\ConfigurableInterface;
/** /**
* Query interface * Query interface.
*/ */
interface QueryInterface extends ConfigurableInterface interface QueryInterface extends ConfigurableInterface
{ {
/** /**
* Get type for this query * Get type for this query.
* *
* @return string * @return string
*/ */
public function getType(); public function getType();
/** /**
* Get the requestbuilder class for this query * Get the requestbuilder class for this query.
* *
* @return RequestBuilderInterface * @return RequestBuilderInterface
*/ */
public function getRequestBuilder(); public function getRequestBuilder();
/** /**
* Get the response parser class for this query * Get the response parser class for this query.
* *
* @return ResponseParserInterface * @return ResponseParserInterface
*/ */
public function getResponseParser(); public function getResponseParser();
/** /**
* Set handler option * Set handler option.
*
* @param string $handler
* *
* @param string $handler * @return self Provides fluent interface
* @return self Provides fluent interface
*/ */
public function setHandler($handler); public function setHandler($handler);
/** /**
* Get handler option * Get handler option.
* *
* @return string * @return string
*/ */
public function getHandler(); public function getHandler();
/** /**
* Set resultclass option * Set resultclass option.
* *
* If you set a custom result class it must be available through autoloading * If you set a custom result class it must be available through autoloading
* or a manual require before calling this method. This is your * or a manual require before calling this method. This is your
...@@ -90,39 +93,41 @@ interface QueryInterface extends ConfigurableInterface ...@@ -90,39 +93,41 @@ interface QueryInterface extends ConfigurableInterface
* *
* Also you need to make sure this class implements the ResultInterface * Also you need to make sure this class implements the ResultInterface
* *
* @param string $classname * @param string $classname
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function setResultClass($classname); public function setResultClass($classname);
/** /**
* Get resultclass option * Get resultclass option.
* *
* @return string * @return string
*/ */
public function getResultClass(); public function getResultClass();
/** /**
* Get a helper instance * Get a helper instance.
* *
* @return Helper * @return Helper
*/ */
public function getHelper(); public function getHelper();
/** /**
* Add extra params to the request * Add extra params to the request.
* *
* Only intended for internal use, for instance with dereferenced params. * Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get * Therefore the params are limited in functionality. Only add and get
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
* @return self Provides fluent interface *
* @return self Provides fluent interface
*/ */
public function addParam($name, $value); public function addParam($name, $value);
/** /**
* Get extra params * Get extra params.
* *
* @return array * @return array
*/ */
......
...@@ -30,25 +30,28 @@ ...@@ -30,25 +30,28 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
use Solarium\Core\Client\Request; use Solarium\Core\Client\Request;
/** /**
* Interface for requestbuilders * Interface for requestbuilders.
*/ */
interface RequestBuilderInterface interface RequestBuilderInterface
{ {
/** /**
* Build request for a select query * Build request for a select query.
*
* @param QueryInterface $query
* *
* @param QueryInterface $query
* @return Request * @return Request
*/ */
public function build(QueryInterface $query); public function build(QueryInterface $query);
......
...@@ -30,16 +30,18 @@ ...@@ -30,16 +30,18 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query; namespace Solarium\Core\Query;
/** /**
* Interface for response parsers * 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
...@@ -50,11 +52,12 @@ namespace Solarium\Core\Query; ...@@ -50,11 +52,12 @@ namespace Solarium\Core\Query;
interface ResponseParserInterface interface ResponseParserInterface
{ {
/** /**
* Get a Result object 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.
* *
* @param \Solarium\Core\Query\Result\Result $result * @param \Solarium\Core\Query\Result\Result $result
*
* @return mixed * @return mixed
*/ */
public function parse($result); public function parse($result);
......
...@@ -30,45 +30,45 @@ ...@@ -30,45 +30,45 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Core\Query\Result; namespace Solarium\Core\Query\Result;
use Solarium\Core\Query\ResponseParserInterface; use Solarium\Core\Query\ResponseParserInterface;
use Solarium\Exception\UnexpectedValueException; use Solarium\Exception\UnexpectedValueException;
/** /**
* QueryType result * QueryType result.
*/ */
class QueryType extends Result class QueryType extends Result
{ {
/** /**
* Lazy load parsing indicator * Lazy load parsing indicator.
* *
* @var bool * @var bool
*/ */
protected $parsed = false; protected $parsed = false;
/** /**
* Parse response into result objects * Parse response into result objects.
* *
* Only runs once * Only runs once
* *
* @throws UnexpectedValueException * @throws UnexpectedValueException
* @return void
*/ */
protected function parseResponse() protected function parseResponse()
{ {
if (!$this->parsed) { if (!$this->parsed) {
$responseParser = $this->query->getResponseParser(); $responseParser = $this->query->getResponseParser();
if (!$responseParser || !($responseParser instanceof ResponseParserInterface)) { if (!$responseParser || !($responseParser instanceof ResponseParserInterface)) {
throw new UnexpectedValueException( throw new UnexpectedValueException(
'No responseparser returned by querytype: '. $this->query->getType() 'No responseparser returned by querytype: '.$this->query->getType()
); );
} }
...@@ -79,10 +79,9 @@ class QueryType extends Result ...@@ -79,10 +79,9 @@ class QueryType extends Result
} }
/** /**
* Map parser data into properties * Map parser data into properties.
* *
* @param array $mapData * @param array $mapData
* @return void
*/ */
protected function mapData($mapData) protected function mapData($mapData)
{ {
......
...@@ -30,16 +30,18 @@ ...@@ -30,16 +30,18 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Exception; namespace Solarium\Exception;
/** /**
* Marker Interface for Solarium exceptions * Marker Interface for Solarium exceptions.
* *
* For background info see http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3 * For background info see http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3
*/ */
......
...@@ -30,18 +30,19 @@ ...@@ -30,18 +30,19 @@
* *
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl> * @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/ * @link http://www.solarium-project.org/
*/ */
/** /**
* @namespace * @namespace
*/ */
namespace Solarium\Exception; namespace Solarium\Exception;
/** /**
* InvalidArgument exception for Solarium classes * InvalidArgument exception for Solarium classes.
*/ */
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{ {
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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