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

Merge branch 'develop' of github.com:solariumphp/solarium into Hywan-phar

# Conflicts:
#	phar/stub.php
parents 3bdaec4c 2bb12fb1
...@@ -6,7 +6,7 @@ php: ...@@ -6,7 +6,7 @@ php:
- 5.4 - 5.4
- 5.3 - 5.3
- hhvm - hhvm
- hhvm-nightly - nightly
env: env:
- SYMFONY_VERSION=2.1.* - SYMFONY_VERSION=2.1.*
...@@ -16,7 +16,7 @@ env: ...@@ -16,7 +16,7 @@ env:
- SYMFONY_VERSION=2.5.* - SYMFONY_VERSION=2.5.*
before_script: before_script:
- bash -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] && [ $TRAVIS_PHP_VERSION != 'hhvm-nightly' ] && [ $TRAVIS_PHP_VERSION != '5.3' ]; then printf '\n\n\n\n' | pecl install pecl_http-1.7.6; fi" - bash -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] && [ $TRAVIS_PHP_VERSION != '5.3' ]; then printf '\n\n\n\n' | pecl install pecl_http-1.7.6; fi"
- composer require --prefer-source --dev symfony/event-dispatcher:${SYMFONY_VERSION} - composer require --prefer-source --dev symfony/event-dispatcher:${SYMFONY_VERSION}
script: vendor/bin/phpunit -c phpunit.xml.travis -v script: vendor/bin/phpunit -c phpunit.xml.travis -v
...@@ -27,4 +27,4 @@ matrix: ...@@ -27,4 +27,4 @@ matrix:
allow_failures: allow_failures:
- php: 5.3 - php: 5.3
- php: hhvm - php: hhvm
- php: hhvm-nightly - php: nightly
\ No newline at end of file
...@@ -43,9 +43,12 @@ http://wiki.solarium-project.org/index.php/V3:Installation#Getting_Solarium ...@@ -43,9 +43,12 @@ http://wiki.solarium-project.org/index.php/V3:Installation#Getting_Solarium
See the COPYING file or view online: See the COPYING file or view online:
https://github.com/solariumphp/solarium/blob/master/COPYING https://github.com/solariumphp/solarium/blob/master/COPYING
## Travis Continuous Integration status ## Continuous Integration status
* Develop branch [![Develop build status](https://secure.travis-ci.org/solariumphp/solarium.png?branch=develop)](http://travis-ci.org/solariumphp/solarium) * Develop branch [![Develop build status](https://secure.travis-ci.org/solariumphp/solarium.png?branch=develop)](http://travis-ci.org/solariumphp/solarium)
* Develop branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=develop)](https://coveralls.io/r/solariumphp/solarium?branch=develop) * Develop branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=develop)](https://coveralls.io/r/solariumphp/solarium?branch=develop)
* Master branch [![Develop build status](https://secure.travis-ci.org/solariumphp/solarium.png?branch=master)](http://travis-ci.org/solariumphp/solarium) * Master branch [![Develop build status](https://secure.travis-ci.org/solariumphp/solarium.png?branch=master)](http://travis-ci.org/solariumphp/solarium)
* Master branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=master)](https://coveralls.io/r/solariumphp/solarium?branch=master) * Master branch [![Coverage Status](https://coveralls.io/repos/solariumphp/solarium/badge.png?branch=master)](https://coveralls.io/r/solariumphp/solarium?branch=master)
* [![SensioLabsInsight](https://insight.sensiolabs.com/projects/292e29f7-10a9-4685-b9ac-37925ebef9ae/small.png)](https://insight.sensiolabs.com/projects/292e29f7-10a9-4685-b9ac-37925ebef9ae)
* [![Total Downloads](https://poser.pugx.org/solarium/solarium/downloads.svg)](https://packagist.org/packages/solarium/solarium)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"description": "PHP Solr client", "description": "PHP Solr client",
"keywords": ["solr", "search", "php"], "keywords": ["solr", "search", "php"],
"homepage": "http://www.solarium-project.org", "homepage": "http://www.solarium-project.org",
"license": "NewBSD", "license": "BSD-3-Clause",
"authors": [ "authors": [
{ {
"name": "See GitHub contributors", "name": "See GitHub contributors",
......
...@@ -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 * @param string $class
* @return void
*/ */
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.4.0'; const VERSION = '3.4.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
...@@ -93,10 +95,11 @@ class Client extends CoreClient ...@@ -93,10 +95,11 @@ class Client extends CoreClient
* - 1.2.4 (higher) * - 1.2.4 (higher)
* *
* *
* @internal a string compare is used instead of version_compare because * 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
...@@ -124,6 +127,7 @@ class Client extends CoreClient ...@@ -124,6 +127,7 @@ class Client extends CoreClient
* - 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 Request $request
* @param Endpoint $endpoint * @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
*/
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 Request $request
* @param Endpoint $endpoint * @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 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
}
/**
* Get the response for a curl handle
* *
* @param resource $handle * @param resource $handle
* @param string $httpResponse * @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 Request $request
* @param Endpoint $endpoint * @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);
...@@ -151,7 +122,7 @@ class Curl extends Configurable implements AdapterInterface ...@@ -151,7 +122,7 @@ class Curl extends Configurable implements AdapterInterface
curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']); curl_setopt($handler, CURLOPT_TIMEOUT, $options['timeout']);
curl_setopt($handler, CURLOPT_CONNECTTIMEOUT, $options['timeout']); curl_setopt($handler, CURLOPT_CONNECTTIMEOUT, $options['timeout']);
if ($proxy = $this->getOption('proxy')) { if (null !== ($proxy = $this->getOption('proxy'))) {
curl_setopt($handler, CURLOPT_PROXY, $proxy); curl_setopt($handler, CURLOPT_PROXY, $proxy);
} }
...@@ -170,14 +141,14 @@ class Curl extends Configurable implements AdapterInterface ...@@ -170,14 +141,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);
} }
...@@ -207,18 +178,73 @@ class Curl extends Configurable implements AdapterInterface ...@@ -207,18 +178,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);
...@@ -230,22 +256,4 @@ class Curl extends Configurable implements AdapterInterface ...@@ -230,22 +256,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 Request $request
* @param Endpoint $endpoint * @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 string $data
* @param array $headers * @param array $headers
* @return void
*/ */
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 Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
*
* @return resource * @return resource
*/ */
public function createContext($request, $endpoint) public function createContext($request, $endpoint)
...@@ -99,8 +104,9 @@ class Http extends Configurable implements AdapterInterface ...@@ -99,8 +104,9 @@ class Http extends Configurable implements AdapterInterface
$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 string $uri
* @param resource $context * @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 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
}
/**
* Execute a Solr request using the Pecl Http
* *
* @throws HttpException * @throws HttpException
*
* @param Request $request * @param Request $request
* @param Endpoint $endpoint * @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 Request $request
* @param Endpoint $endpoint * @param Endpoint $endpoint
* @param HttpRequest *
* @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;
}
} }
...@@ -140,7 +140,7 @@ class Zend2Http extends Configurable implements AdapterInterface ...@@ -140,7 +140,7 @@ class Zend2Http extends Configurable implements AdapterInterface
*/ */
public function getZendHttp() public function getZendHttp()
{ {
if (null == $this->zendHttp) { if (null === $this->zendHttp) {
$options = array(); $options = array();
// forward zendhttp options // forward zendhttp options
......
...@@ -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.
* *
...@@ -85,6 +87,7 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -85,6 +87,7 @@ class ZendHttp extends Configurable implements AdapterInterface
* *
* @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,13 +111,14 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -109,13 +111,14 @@ 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.
...@@ -139,7 +142,7 @@ class ZendHttp extends Configurable implements AdapterInterface ...@@ -139,7 +142,7 @@ class ZendHttp extends Configurable implements AdapterInterface
*/ */
public function getZendHttp() public function getZendHttp()
{ {
if (null == $this->zendHttp) { if (null === $this->zendHttp) {
$options = array(); $options = array();
// forward zendhttp options // forward zendhttp 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 Request $request
* @param Endpoint $endpoint * @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 Request $request
* @param \Zend_Http_Response $response * @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.
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,9 +75,10 @@ class Endpoint extends Configurable ...@@ -90,9 +75,10 @@ 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,9 +87,10 @@ class Endpoint extends Configurable ...@@ -101,9 +87,10 @@ 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,11 +131,12 @@ class Endpoint extends Configurable ...@@ -143,11 +131,12 @@ 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,9 +159,10 @@ class Endpoint extends Configurable ...@@ -170,9 +159,10 @@ 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,12 +244,13 @@ class Endpoint extends Configurable ...@@ -252,12 +244,13 @@ 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 * @param array $headers
* @return void
*/ */
public function setHeaders($headers) public function setHeaders($headers)
{ {
...@@ -147,7 +149,7 @@ class Response ...@@ -147,7 +149,7 @@ class Response
} }
} }
if (null == $statusHeader) { if (null === $statusHeader) {
throw new HttpException("No HTTP status found"); throw new HttpException("No HTTP status found");
} }
......
...@@ -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,6 +67,7 @@ class Configurable implements ConfigurableInterface ...@@ -66,6 +67,7 @@ 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 array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false * @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed) * for merging (new values overwrite old ones if needed)
*
* @return void
*/ */
public function setOptions($options, $overwrite = false) public function setOptions($options, $overwrite = false)
{ {
...@@ -107,7 +108,7 @@ class Configurable implements ConfigurableInterface ...@@ -107,7 +108,7 @@ class Configurable implements ConfigurableInterface
} }
} }
if (true == $overwrite) { if (true === $overwrite) {
$this->options = $options; $this->options = $options;
} else { } else {
$this->options = array_merge($this->options, $options); $this->options = array_merge($this->options, $options);
...@@ -119,7 +120,35 @@ class Configurable implements ConfigurableInterface ...@@ -119,7 +120,35 @@ class Configurable implements ConfigurableInterface
} }
/** /**
* Initialization hook * Get an option value by name.
*
* If the option is empty or not set a NULL value will be returned.
*
* @param string $name
*
* @return mixed
*/
public function getOption($name)
{
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return;
}
}
/**
* Get all options.
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/**
* Initialization hook.
* *
* Can be used by classes for special behaviour. For instance some options * 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 * have extra setup work in their 'set' method that also need to be called
...@@ -128,22 +157,20 @@ class Configurable implements ConfigurableInterface ...@@ -128,22 +157,20 @@ class Configurable implements ConfigurableInterface
* This hook is called by the constructor after saving the constructor * This hook is called by the constructor after saving the constructor
* arguments in {@link $options} * arguments in {@link $options}
* *
* @internal This empty implementation can optionally be implemented in * This empty implementation can optionally be implemented in
* descending classes. It's not an abstract method on purpose, there are * descending classes. It's not an abstract method on purpose, there are
* many cases where no initialization is needed. * many cases where no initialization is needed.
*
* @return void
*/ */
protected function init() protected function init()
{ {
} }
/** /**
* Set an option * Set an option.
* *
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
*
* @return self Provides fluent interface * @return self Provides fluent interface
*/ */
protected function setOption($name, $value) protected function setOption($name, $value)
...@@ -153,43 +180,16 @@ class Configurable implements ConfigurableInterface ...@@ -153,43 +180,16 @@ class Configurable implements ConfigurableInterface
return $this; return $this;
} }
/**
* Get an option value by name
*
* If the option is empty or not set a NULL value will be returned.
*
* @param string $name
* @return mixed
*/
public function getOption($name)
{
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return null;
}
}
/**
* Get all options
*
* @return array
*/
public function getOptions()
{
return $this->options;
}
/** /**
* 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 array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false * @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed) * for merging (new values overwrite old ones if needed)
*
* @return void
*/ */
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
{ {
...@@ -64,7 +66,7 @@ class PostExecuteRequest extends Event ...@@ -64,7 +66,7 @@ class PostExecuteRequest extends Event
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
{ {
...@@ -64,7 +66,7 @@ class PreExecuteRequest extends Event ...@@ -64,7 +66,7 @@ class PreExecuteRequest extends Event
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,43 +30,45 @@ ...@@ -30,43 +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; 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
...@@ -95,6 +97,7 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -95,6 +97,7 @@ abstract class Query extends Configurable implements QueryInterface
* 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,9 +138,10 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -134,9 +138,10 @@ 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,13 +176,14 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -171,13 +176,14 @@ 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,9 +204,10 @@ abstract class Query extends Configurable implements QueryInterface ...@@ -198,9 +204,10 @@ 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,29 +95,30 @@ abstract class RequestBuilder implements RequestBuilderInterface ...@@ -90,29 +95,30 @@ 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) {
$value = (true == $value) ? 'true' : 'false'; $value = (true === (bool)$value) ? 'true' : 'false';
return $this->attrib($name, $value); return $this->attrib($name, $value);
} else { } else {
...@@ -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)
...@@ -56,9 +59,9 @@ abstract class ResponseParser ...@@ -56,9 +59,9 @@ abstract class ResponseParser
// key counter to convert values to arrays when keys are re-used // key counter to convert values to arrays when keys are re-used
$keys = array(); $keys = array();
$dataCount = count($data);
$result = array(); $result = array();
for ($i = 0; $i < count($data); $i += 2) { for ($i = 0; $i < $dataCount; $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 +80,11 @@ abstract class ResponseParser ...@@ -77,10 +80,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 $data
* @param array $result * @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
...@@ -91,38 +94,40 @@ interface QueryInterface extends ConfigurableInterface ...@@ -91,38 +94,40 @@ 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);
......
This diff is collapsed.
This diff is collapsed.
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