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:
- 5.4
- 5.3
- hhvm
- hhvm-nightly
- nightly
env:
- SYMFONY_VERSION=2.1.*
......@@ -16,7 +16,7 @@ env:
- SYMFONY_VERSION=2.5.*
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}
script: vendor/bin/phpunit -c phpunit.xml.travis -v
......@@ -27,4 +27,4 @@ matrix:
allow_failures:
- php: 5.3
- php: hhvm
- php: hhvm-nightly
\ No newline at end of file
- php: nightly
......@@ -43,9 +43,12 @@ http://wiki.solarium-project.org/index.php/V3:Installation#Getting_Solarium
See the COPYING file or view online:
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 [![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 [![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 @@
"description": "PHP Solr client",
"keywords": ["solr", "search", "php"],
"homepage": "http://www.solarium-project.org",
"license": "NewBSD",
"license": "BSD-3-Clause",
"authors": [
{
"name": "See GitHub contributors",
......
......@@ -3,7 +3,7 @@ require(__DIR__.'/init.php');
use Solarium\Core\Event\Events;
// 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 $output = array();
......
<?php
require(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\Core\Plugin\Plugin;
use Solarium\Core\Plugin\AbstractPlugin;
use Solarium\QueryType\Select\Query\Query as Select;
// This is a custom query class that could have some customized logic
......@@ -11,7 +11,7 @@ class MyQuery extends Select
}
// this very simple plugin that modifies the default querytype mapping
class QueryCustomizer extends Plugin
class QueryCustomizer extends AbstractPlugin
{
public function initPlugin($client, $options)
{
......
......@@ -30,16 +30,18 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium;
/**
* Autoloader
* 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;
class Autoloader
{
/**
* Register the Solarium autoloader
* Register the Solarium autoloader.
*
* The autoloader only acts for classnames that start with 'Solarium'. It
* will be appended to any other autoloaders already registered.
......@@ -61,36 +63,34 @@ class Autoloader
* you want to use multiple autoloaders please use spl_autoload_register.
*
* @static
* @return void
*/
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.
* The autoloader only acts for classnames that start with 'Solarium'.
*
* @static
* @param string $class
* @return void
*
* @param string $class
*/
public static function load($class)
{
if (substr($class, 0, 8) == 'Solarium') {
$class = str_replace(
array('Solarium', '\\'),
array('', '/'),
$class
);
$file = dirname(__FILE__) . $class . '.php';
$file = dirname(__FILE__).$class.'.php';
require($file);
require $file;
}
}
}
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium;
use Solarium\Core\Client\Client as CoreClient;
......@@ -47,7 +49,7 @@ use Solarium\Core\Client\Client as 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
*
......@@ -73,7 +75,7 @@ class Client extends CoreClient
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
* optional. If you only care for major and minor versions you can use
......@@ -93,10 +95,11 @@ class Client extends CoreClient
* - 1.2.4 (higher)
*
*
* @internal a string compare is used instead of version_compare because
* version_compare returns false for a compare of 1.0.0 with 1.0
* A string compare is used instead of version_compare because
* version_compare returns false for a compare of 1.0.0 with 1.0
*
* @param string $version
*
* @param string $version
* @return boolean
*/
public static function checkExact($version)
......@@ -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
* optional. If you only care for major and minor versions you can use
......@@ -123,7 +126,8 @@ class Client extends CoreClient
* - 2 (the actual version is lower)
* - 1.3 (the actual version is lower)
*
* @param string $version
* @param string $version
*
* @return boolean
*/
public static function checkMinimal($version)
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\ConfigurableInterface;
......@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
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
* result object. This is actually quite a complex task as it involves the
......@@ -61,10 +63,11 @@ use Solarium\Core\Client\Endpoint;
interface AdapterInterface extends ConfigurableInterface
{
/**
* Execute a request
* Execute a request.
*
* @param Request $request
* @param Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
* @return Response
*/
public function execute($request, $endpoint);
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
......@@ -47,35 +49,18 @@ use Solarium\Exception\RuntimeException;
use Solarium\Exception\HttpException;
/**
* cURL HTTP adapter
* cURL HTTP adapter.
*
* @author Intervals <info@myintervals.com>
*/
class Curl extends Configurable implements AdapterInterface
{
/**
* Initialization hook
*
* Checks the availability of Curl_http
* Execute a Solr request using the 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 Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
* @return Response
*/
public function execute($request, $endpoint)
......@@ -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 string $httpResponse
*
* @param resource $handle
* @param string $httpResponse
* @return Response
*/
public function getResponse($handle, $httpResponse)
......@@ -114,7 +83,7 @@ class Curl extends Configurable implements AdapterInterface
$data = $httpResponse;
$info = curl_getinfo($handle);
$headers = array();
$headers[] = 'HTTP/1.1 ' . $info['http_code']. ' OK';
$headers[] = 'HTTP/1.1 '.$info['http_code'].' OK';
} else {
$headers = array();
$data = '';
......@@ -128,17 +97,19 @@ class Curl extends Configurable implements AdapterInterface
}
/**
* Create curl handle for a request
* Create curl handle for a request.
*
* @throws InvalidArgumentException
* @param Request $request
* @param Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
*
* @return resource
*/
public function createHandle($request, $endpoint)
{
// @codeCoverageIgnoreStart
$uri = $endpoint->getBaseUri() . $request->getUri();
$uri = $endpoint->getBaseUri().$request->getUri();
$method = $request->getMethod();
$options = $this->createOptions($request, $endpoint);
......@@ -151,7 +122,7 @@ class Curl extends Configurable implements AdapterInterface
curl_setopt($handler, CURLOPT_TIMEOUT, $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);
}
......@@ -170,14 +141,14 @@ class Curl extends Configurable implements AdapterInterface
}
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);
}
if (count($options['headers'])) {
$headers = array();
foreach ($options['headers'] as $key => $value) {
$headers[] = $key . ": " . $value;
$headers[] = $key.": ".$value;
}
curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
}
......@@ -207,18 +178,73 @@ class Curl extends Configurable implements AdapterInterface
// @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.
*
* @param Request $request
* @param Endpoint $endpoint
* @param Request $request
* @param Endpoint $endpoint
*
* @return array
*/
protected function createOptions($request, $endpoint)
{
// @codeCoverageIgnoreStart
$options = array(
'timeout' => $endpoint->getTimeout()
'timeout' => $endpoint->getTimeout(),
);
foreach ($request->getHeaders() as $headerLine) {
list($header, $value) = explode(':', $headerLine);
......@@ -230,22 +256,4 @@ class Curl extends Configurable implements AdapterInterface
return $options;
// @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 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
......@@ -45,22 +47,24 @@ use Solarium\Core\Client\Endpoint;
use Solarium\Exception\HttpException;
/**
* Basic HTTP adapter using a stream
* Basic HTTP adapter using a stream.
*/
class Http extends Configurable implements AdapterInterface
{
/**
* Handle Solr communication
* Handle Solr communication.
*
* @throws HttpException
* @param Request $request
* @param Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
*
* @return Response
*/
public function execute($request, $endpoint)
{
$context = $this->createContext($request, $endpoint);
$uri = $endpoint->getBaseUri() . $request->getUri();
$uri = $endpoint->getBaseUri().$request->getUri();
list($data, $headers) = $this->getData($uri, $context);
......@@ -70,12 +74,12 @@ class Http extends Configurable implements AdapterInterface
}
/**
* Check result of a request
* Check result of a request.
*
* @throws HttpException
* @param string $data
* @param array $headers
* @return void
*
* @param string $data
* @param array $headers
*/
public function check($data, $headers)
{
......@@ -87,10 +91,11 @@ class Http extends Configurable implements AdapterInterface
}
/**
* Create a stream context for a request
* Create a stream context for a request.
*
* @param Request $request
* @param Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
* @return resource
*/
public function createContext($request, $endpoint)
......@@ -98,9 +103,10 @@ class Http extends Configurable implements AdapterInterface
$method = $request->getMethod();
$context = stream_context_create(
array('http' => array(
'method' => $method,
'timeout' => $endpoint->getTimeout()
))
'method' => $method,
'timeout' => $endpoint->getTimeout(),
),
)
);
if ($method == Request::METHOD_POST) {
......@@ -135,7 +141,7 @@ class Http extends Configurable implements AdapterInterface
if (!empty($authData['username']) && !empty($authData['password'])) {
$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
}
/**
* Execute request
* Execute request.
*
* @param string $uri
* @param resource $context
*
* @param string $uri
* @param resource $context
* @return array
*/
protected function getData($uri, $context)
......
......@@ -31,12 +31,14 @@
*
* @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
......@@ -48,36 +50,20 @@ use Solarium\Exception\HttpException;
use Solarium\Exception\InvalidArgumentException;
/**
* Pecl HTTP adapter
* Pecl HTTP adapter.
*
* @author Gasol Wu <gasol.wu@gmail.com>
*/
class PeclHttp extends Configurable implements AdapterInterface
{
/**
* Initialization hook
* Execute a Solr request using the Pecl Http.
*
* Checks the availability of pecl_http
* @throws HttpException
*
* @throws RuntimeException
*/
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
* @param Request $request
* @param Endpoint $endpoint
*
* @throws HttpException
* @param Request $request
* @param Endpoint $endpoint
* @return Response
*/
public function execute($request, $endpoint)
......@@ -97,37 +83,7 @@ class PeclHttp extends Configurable implements AdapterInterface
}
/**
* 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;
}
/**
*
* adapt Request to HttpRequest
* adapt Request to HttpRequest.
*
* {@link http://us.php.net/manual/en/http.constants.php
* HTTP Predefined Constant}
......@@ -136,14 +92,15 @@ class PeclHttp extends Configurable implements AdapterInterface
* HttpRequest options}
*
* @throws InvalidArgumentException
* @param Request $request
* @param Endpoint $endpoint
* @param HttpRequest
*
* @param Request $request
* @param Endpoint $endpoint
*
* @return \HttpRequest
*/
public function toHttpRequest($request, $endpoint)
{
$url = $endpoint->getBaseUri() . $request->getUri();
$url = $endpoint->getBaseUri().$request->getUri();
$httpRequest = new \HttpRequest($url);
$headers = array();
......@@ -161,7 +118,7 @@ class PeclHttp extends Configurable implements AdapterInterface
}
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()) {
......@@ -188,7 +145,7 @@ class PeclHttp extends Configurable implements AdapterInterface
break;
default:
throw new InvalidArgumentException(
'Unsupported method: ' . $request->getMethod()
'Unsupported method: '.$request->getMethod()
);
}
......@@ -204,4 +161,50 @@ class PeclHttp extends Configurable implements AdapterInterface
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
*/
public function getZendHttp()
{
if (null == $this->zendHttp) {
if (null === $this->zendHttp) {
$options = array();
// forward zendhttp options
......
......@@ -32,12 +32,14 @@
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @copyright Copyright 2012 Alexander Brausewetter <alex@helpdeskhq.com>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client\Adapter;
use Solarium\Core\Configurable;
......@@ -49,7 +51,7 @@ use Solarium\Exception\HttpException;
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
* configuration options. For more info see the manual at
......@@ -60,7 +62,7 @@ use Solarium\Exception\OutOfBoundsException;
class ZendHttp extends Configurable implements AdapterInterface
{
/**
* Zend Http instance for communication with Solr
* Zend Http instance for communication with Solr.
*
* @var \Zend_Http_Client
*/
......@@ -72,7 +74,7 @@ class ZendHttp extends Configurable implements AdapterInterface
protected $timeout;
/**
* Set options
* Set options.
*
* Overrides any existing values.
*
......@@ -83,9 +85,10 @@ class ZendHttp extends Configurable implements AdapterInterface
* The $options param should be an array or an object that has a toArray
* method, like Zend_Config
*
* @param array|object $options
* @param boolean $overwrite
* @return self Provides fluent interface
* @param array|object $options
* @param boolean $overwrite
*
* @return self Provides fluent interface
*/
public function setOptions($options, $overwrite = false)
{
......@@ -93,7 +96,6 @@ class ZendHttp extends Configurable implements AdapterInterface
// forward options to zendHttp instance
if (null !== $this->zendHttp) {
// forward timeout setting
$adapterOptions = array();
......@@ -109,14 +111,15 @@ class ZendHttp extends Configurable implements AdapterInterface
}
/**
* Set the Zend_Http_Client instance
* Set the Zend_Http_Client instance.
*
* This method is optional, if you don't set a client it will be created
* upon first use, using default and/or custom options (the most common use
* case)
*
* @param \Zend_Http_Client $zendHttp
* @return self Provides fluent interface
* @param \Zend_Http_Client $zendHttp
*
* @return self Provides fluent interface
*/
public function setZendHttp($zendHttp)
{
......@@ -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
* options.
......@@ -139,7 +142,7 @@ class ZendHttp extends Configurable implements AdapterInterface
*/
public function getZendHttp()
{
if (null == $this->zendHttp) {
if (null === $this->zendHttp) {
$options = array();
// forward zendhttp options
......@@ -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 OutOfBoundsException
* @param Request $request
* @param Endpoint $endpoint
*
* @param Request $request
* @param Endpoint $endpoint
*
* @return Response
*/
public function execute($request, $endpoint)
......@@ -190,11 +195,11 @@ class ZendHttp extends Configurable implements AdapterInterface
$client->setParameterGet($request->getParams());
break;
default:
throw new OutOfBoundsException('Unsupported method: ' . $request->getMethod());
throw new OutOfBoundsException('Unsupported method: '.$request->getMethod());
break;
}
$client->setUri($endpoint->getBaseUri() . $request->getHandler());
$client->setUri($endpoint->getBaseUri().$request->getHandler());
$client->setHeaders($request->getHeaders());
$this->timeout = $endpoint->getTimeout();
......@@ -208,11 +213,13 @@ class ZendHttp extends Configurable implements AdapterInterface
/**
* Prepare a solarium response from the given request and client
* response
* response.
*
* @throws HttpException
* @param Request $request
* @param \Zend_Http_Response $response
*
* @param Request $request
* @param \Zend_Http_Response $response
*
* @return Response
*/
protected function prepareResponse($request, $response)
......@@ -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 Request $request
* @return void
* @param \Zend_Http_Client $client
* @param Request $request
*/
protected function prepareFileUpload($client, $request)
{
......
This diff is collapsed.
This diff is collapsed.
......@@ -30,23 +30,25 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client;
use Solarium\Core\Configurable;
/**
* Class for describing an endpoint
* Class for describing an endpoint.
*/
class Endpoint extends Configurable
{
/**
* Default options
* Default options.
*
* The defaults match a standard Solr example instance as distributed by
* the Apache Lucene Solr project.
......@@ -63,24 +65,7 @@ class Endpoint extends Configurable
);
/**
* 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;
}
}
}
/**
* Get key value
* Get key value.
*
* @return string
*/
......@@ -90,10 +75,11 @@ class Endpoint extends Configurable
}
/**
* Set key value
* Set key value.
*
* @param string $value
* @return self Provides fluent interface
* @param string $value
*
* @return self Provides fluent interface
*/
public function setKey($value)
{
......@@ -101,10 +87,11 @@ class Endpoint extends Configurable
}
/**
* Set host option
* Set host option.
*
* @param string $host This can be a hostname or an IP address
*
* @param string $host This can be a hostname or an IP address
* @return self Provides fluent interface
* @return self Provides fluent interface
*/
public function setHost($host)
{
......@@ -112,7 +99,7 @@ class Endpoint extends Configurable
}
/**
* Get host option
* Get host option.
*
* @return string
*/
......@@ -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
*/
public function setPort($port)
......@@ -133,7 +121,7 @@ class Endpoint extends Configurable
}
/**
* Get port option
* Get port option.
*
* @return int
*/
......@@ -143,12 +131,13 @@ class Endpoint extends Configurable
}
/**
* Set path option
* Set path option.
*
* If the path has a trailing slash it will be removed.
*
* @param string $path
* @return self Provides fluent interface
* @param string $path
*
* @return self Provides fluent interface
*/
public function setPath($path)
{
......@@ -160,7 +149,7 @@ class Endpoint extends Configurable
}
/**
* Get path option
* Get path option.
*
* @return string
*/
......@@ -170,10 +159,11 @@ class Endpoint extends Configurable
}
/**
* Set core option
* Set core option.
*
* @param string $core
*
* @param string $core
* @return self Provides fluent interface
* @return self Provides fluent interface
*/
public function setCore($core)
{
......@@ -181,7 +171,7 @@ class Endpoint extends Configurable
}
/**
* Get core option
* Get core option.
*
* @return string
*/
......@@ -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
*/
public function setTimeout($timeout)
......@@ -202,7 +193,7 @@ class Endpoint extends Configurable
}
/**
* Get timeout option
* Get timeout option.
*
* @return string
*/
......@@ -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
*/
public function setScheme($scheme)
......@@ -223,7 +215,7 @@ class Endpoint extends Configurable
}
/**
* Get scheme option
* Get scheme option.
*
* @return string
*/
......@@ -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.
*
......@@ -241,7 +233,7 @@ class Endpoint extends Configurable
*/
public function getBaseUri()
{
$uri = $this->getScheme() . '://' . $this->getHost() . ':' . $this->getPort() . $this->getPath() . '/';
$uri = $this->getScheme().'://'.$this->getHost().':'.$this->getPort().$this->getPath().'/';
$core = $this->getCore();
if (!empty($core)) {
......@@ -252,13 +244,14 @@ class Endpoint extends Configurable
}
/**
* Set HTTP basic auth settings
* Set HTTP basic auth settings.
*
* If one or both values are NULL authentication will be disabled
*
* @param string $username
* @param string $password
* @return self Provides fluent interface
* @param string $username
* @param string $password
*
* @return self Provides fluent interface
*/
public function setAuthentication($username, $password)
{
......@@ -269,7 +262,7 @@ class Endpoint extends Configurable
}
/**
* Get HTTP basic auth settings
* Get HTTP basic auth settings.
*
* @return array
*/
......@@ -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
* note: uri resource is decoded for readability
......@@ -291,15 +284,26 @@ class Endpoint extends Configurable
*/
public function __toString()
{
$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);
$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);
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 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Client;
use Solarium\Exception\HttpException;
/**
* Class for describing a response
* Class for describing a response.
*/
class Response
{
/**
* Headers
* Headers.
*
* @var array
*/
protected $headers;
/**
* Body
* Body.
*
* @var string
*/
protected $body;
/**
* HTTP response code
* HTTP response code.
*
* @var int
*/
protected $statusCode;
/**
* HTTP response message
* HTTP response message.
*
* @var string
*/
protected $statusMessage;
/**
* Constructor
* Constructor.
*
* @param string $body
* @param array $headers
......@@ -88,7 +90,7 @@ class Response
}
/**
* Get body data
* Get body data.
*
* @return string
*/
......@@ -98,7 +100,7 @@ class Response
}
/**
* Get response headers
* Get response headers.
*
* @return array
*/
......@@ -108,7 +110,7 @@ class Response
}
/**
* Get status code
* Get status code.
*
* @return int
*/
......@@ -118,7 +120,7 @@ class Response
}
/**
* Get status message
* Get status message.
*
* @return string
*/
......@@ -128,11 +130,11 @@ class Response
}
/**
* Set headers
* Set headers.
*
* @throws HttpException
* @param array $headers
* @return void
*
* @param array $headers
*/
public function setHeaders($headers)
{
......@@ -147,7 +149,7 @@ class Response
}
}
if (null == $statusHeader) {
if (null === $statusHeader) {
throw new HttpException("No HTTP status found");
}
......
......@@ -30,18 +30,20 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core;
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
* setOption calls. This is the base for many Solarium classes, providing a
......@@ -50,15 +52,14 @@ use Solarium\Exception\InvalidArgumentException;
class Configurable implements ConfigurableInterface
{
/**
* Default options
* Default options.
*
* @var array
*/
protected $options = array(
);
protected $options = array();
/**
* Constructor
* Constructor.
*
* If options are passed they will be merged with {@link $options} using
* the {@link setOptions()} method.
......@@ -66,7 +67,8 @@ class Configurable implements ConfigurableInterface
* After handling the options the {@link _init()} method is called.
*
* @throws InvalidArgumentException
* @param array|\Zend_Config $options
*
* @param array|\Zend_Config $options
*/
public function __construct($options = null)
{
......@@ -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
* its toArray method. This is compatible with the Zend_Config classes in
......@@ -87,11 +89,10 @@ class Configurable implements ConfigurableInterface
* be used instead.
*
* @throws InvalidArgumentException
* @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*
* @return void
* @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*/
public function setOptions($options, $overwrite = false)
{
......@@ -107,7 +108,7 @@ class Configurable implements ConfigurableInterface
}
}
if (true == $overwrite) {
if (true === $overwrite) {
$this->options = $options;
} else {
$this->options = array_merge($this->options, $options);
......@@ -119,77 +120,76 @@ class Configurable implements ConfigurableInterface
}
/**
* Initialization hook
*
* Can be used by classes for special behaviour. For instance some options
* have extra setup work in their 'set' method that also need to be called
* when the option is passed as a constructor argument.
* Get an option value by name.
*
* This hook is called by the constructor after saving the constructor
* arguments in {@link $options}
* If the option is empty or not set a NULL value will be returned.
*
* @internal This empty implementation can optionally be implemented in
* descending classes. It's not an abstract method on purpose, there are
* many cases where no initialization is needed.
* @param string $name
*
* @return void
* @return mixed
*/
protected function init()
public function getOption($name)
{
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return;
}
}
/**
* Set an option
* Get all options.
*
* @param string $name
* @param mixed $value
* @return self Provides fluent interface
* @return array
*/
protected function setOption($name, $value)
public function getOptions()
{
$this->options[$name] = $value;
return $this;
return $this->options;
}
/**
* Get an option value by name
* Initialization hook.
*
* If the option is empty or not set a NULL value will be returned.
* Can be used by classes for special behaviour. For instance some options
* have extra setup work in their 'set' method that also need to be called
* when the option is passed as a constructor argument.
*
* @param string $name
* @return mixed
* This hook is called by the constructor after saving the constructor
* arguments in {@link $options}
*
* This empty implementation can optionally be implemented in
* descending classes. It's not an abstract method on purpose, there are
* many cases where no initialization is needed.
*/
public function getOption($name)
protected function init()
{
if (isset($this->options[$name])) {
return $this->options[$name];
} else {
return null;
}
}
/**
* Get all options
* Set an option.
*
* @return array
* @param string $name
* @param mixed $value
*
* @return self Provides fluent interface
*/
public function getOptions()
protected function setOption($name, $value)
{
return $this->options;
$this->options[$name] = $value;
return $this;
}
/**
* Turns an object array into an associative multidimensional array.
*
* @param $object
*
* @return array|object
*/
protected function toArray($object)
{
if (is_object($object))
{
if (is_object($object)) {
// get_object_vars() does not handle recursive objects well,
// so use set-type without scope operator instead
settype($object, 'array');
......@@ -200,7 +200,9 @@ class Configurable implements ConfigurableInterface
* Using __METHOD__ (Magic constant)
* for recursive call
*/
if (is_array($object)) return array_map(__METHOD__, $object);
if (is_array($object)) {
return array_map(__METHOD__, $object);
}
return $object;
}
......
......@@ -30,18 +30,20 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core;
use Solarium\Exception\InvalidArgumentException;
/**
* Interface for configurable classes
* Interface for configurable classes.
*
* All classes implementing this interface are configurable using the constructor or
* setOption calls. This is the base for many Solarium classes, providing a
......@@ -49,35 +51,34 @@ use Solarium\Exception\InvalidArgumentException;
*/
interface ConfigurableInterface
{
/**
* Set options
* Set options.
*
* If $options is an object it will be converted into an array by called
* it's toArray method. This is compatible with the Zend_Config classes in
* Zend Framework, but can also easily be implemented in any other object.
*
* @throws InvalidArgumentException
* @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*
* @return void
* @param array|\Zend_Config $options
* @param boolean $overwrite True for overwriting existing options, false
* for merging (new values overwrite old ones if needed)
*/
public function setOptions($options, $overwrite = false);
/**
* 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.
*
* @param string $name
* @param string $name
*
* @return mixed
*/
public function getOption($name);
/**
* Get all options
* Get all options.
*
* @return array
*/
......
......@@ -30,16 +30,18 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
/**
* Event definitions
* Event definitions.
*/
class Events
{
......@@ -64,7 +66,7 @@ class Events
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.
*
......@@ -82,7 +84,7 @@ class Events
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.
*
......@@ -91,7 +93,7 @@ class Events
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.
*
......
......@@ -30,19 +30,21 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\Core\Query\QueryInterface;
/**
* PostCreateQuery event, see Events for details
* PostCreateQuery event, see Events for details.
*/
class PostCreateQuery extends Event
{
......@@ -62,7 +64,7 @@ class PostCreateQuery extends Event
protected $options;
/**
* Event constructor
* Event constructor.
*
* @param string $type
* @param array $options
......@@ -76,7 +78,7 @@ class PostCreateQuery extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -86,7 +88,7 @@ class PostCreateQuery extends Event
}
/**
* Get the querytype for this event
* Get the querytype for this event.
*
* @return string
*/
......@@ -96,7 +98,7 @@ class PostCreateQuery extends Event
}
/**
* Get the options for this event
* Get the options for this event.
*
* @return string
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Client\Request;
/**
* PostCreateRequest event, see Events for details
* PostCreateRequest event, see Events for details.
*/
class PostCreateRequest extends Event
{
......@@ -58,7 +60,7 @@ class PostCreateRequest extends Event
protected $request;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
* @param Request $request
......@@ -70,7 +72,7 @@ class PostCreateRequest extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -80,7 +82,7 @@ class PostCreateRequest extends Event
}
/**
* Get the request object for this event
* Get the request object for this event.
*
* @return Request
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\ResultInterface;
/**
* PostCreateResult event, see Events for details
* PostCreateResult event, see Events for details.
*/
class PostCreateResult extends Event
{
......@@ -64,7 +66,7 @@ class PostCreateResult extends Event
protected $result;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
* @param Response $response
......@@ -78,7 +80,7 @@ class PostCreateResult extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -88,7 +90,7 @@ class PostCreateResult extends Event
}
/**
* Get the response object for this event
* Get the response object for this event.
*
* @return Response
*/
......@@ -98,7 +100,7 @@ class PostCreateResult extends Event
}
/**
* Get the result object for this event
* Get the result object for this event.
*
* @return ResultInterface
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result\ResultInterface;
/**
* PostExecute event, see Events for details
* PostExecute event, see Events for details.
*/
class PostExecute extends Event
{
......@@ -58,7 +60,7 @@ class PostExecute extends Event
protected $result;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
* @param ResultInterface $result
......@@ -70,7 +72,7 @@ class PostExecute extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -80,7 +82,7 @@ class PostExecute extends Event
}
/**
* Get the result object for this event
* Get the result object for this event.
*
* @return ResultInterface
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
/**
* PostExecuteRequest event, see Events for details
* PostExecuteRequest event, see Events for details.
*/
class PostExecuteRequest extends Event
{
......@@ -54,17 +56,17 @@ class PostExecuteRequest extends Event
protected $request;
/**
* @var Endpoint
*/
* @var Endpoint
*/
protected $endpoint;
/**
* @var Response
*/
* @var Response
*/
protected $response;
/**
* Event constructor
* Event constructor.
*
* @param Request $request
* @param Endpoint $endpoint
......@@ -78,7 +80,7 @@ class PostExecuteRequest extends Event
}
/**
* Get the endpoint object for this event
* Get the endpoint object for this event.
*
* @return Endpoint
*/
......@@ -88,7 +90,7 @@ class PostExecuteRequest extends Event
}
/**
* Get the response object for this event
* Get the response object for this event.
*
* @return Response
*/
......@@ -98,7 +100,7 @@ class PostExecuteRequest extends Event
}
/**
* Get the request object for this event
* Get the request object for this event.
*
* @return Request
*/
......
......@@ -30,19 +30,21 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
use Solarium\Core\Query\QueryInterface;
/**
* PreCreateQuery event, see Events for details
* PreCreateQuery event, see Events for details.
*/
class PreCreateQuery extends Event
{
......@@ -62,7 +64,7 @@ class PreCreateQuery extends Event
protected $options;
/**
* Event constructor
* Event constructor.
*
* @param string $type
* @param array|null $options
......@@ -74,7 +76,7 @@ class PreCreateQuery extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -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
* @return void
* @param QueryInterface $query
*/
public function setQuery($query)
{
......@@ -95,7 +96,7 @@ class PreCreateQuery extends Event
}
/**
* Get the querytype for this event
* Get the querytype for this event.
*
* @return string
*/
......@@ -105,7 +106,7 @@ class PreCreateQuery extends Event
}
/**
* Get the options for this event
* Get the options for this event.
*
* @return array|null
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Client\Request;
/**
* PreCreateRequest event, see Events for details
* PreCreateRequest event, see Events for details.
*/
class PreCreateRequest extends Event
{
......@@ -58,7 +60,7 @@ class PreCreateRequest extends Event
protected $request;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
*/
......@@ -68,7 +70,7 @@ class PreCreateRequest extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -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
*
* @param Request $request
* @return void
* @param Request $request
*/
public function setRequest(Request $request)
{
......@@ -91,7 +92,7 @@ class PreCreateRequest extends Event
}
/**
* Get the result
* Get the result.
*
* @return null|Request
*/
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\ResultInterface;
/**
* PreCreateResult event, see Events for details
* PreCreateResult event, see Events for details.
*/
class PreCreateResult extends Event
{
......@@ -64,7 +66,7 @@ class PreCreateResult extends Event
protected $result;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
* @param Response $response
......@@ -76,7 +78,7 @@ class PreCreateResult extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -86,7 +88,7 @@ class PreCreateResult extends Event
}
/**
* Get the response object for this event
* Get the response object for this event.
*
* @return Response
*/
......@@ -96,7 +98,7 @@ class PreCreateResult extends Event
}
/**
* Get the result object for this event
* Get the result object for this event.
*
* @return ResultInterface
*/
......@@ -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
* @return void
* @param ResultInterface $result
*/
public function setResult($result)
{
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -43,7 +45,7 @@ use Solarium\Core\Query\QueryInterface;
use Solarium\Core\Query\Result\ResultInterface;
/**
* PostExecute event, see Events for details
* PostExecute event, see Events for details.
*/
class PreExecute extends Event
{
......@@ -58,7 +60,7 @@ class PreExecute extends Event
protected $result;
/**
* Event constructor
* Event constructor.
*
* @param QueryInterface $query
*/
......@@ -68,7 +70,7 @@ class PreExecute extends Event
}
/**
* Get the query object for this event
* Get the query object for this event.
*
* @return QueryInterface
*/
......@@ -78,7 +80,7 @@ class PreExecute extends Event
}
/**
* Get the result object for this event
* Get the result object for this event.
*
* @return ResultInterface
*/
......@@ -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
* @return void
* @param ResultInterface $result
*/
public function setResult($result)
{
......
......@@ -30,12 +30,14 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Event;
use Symfony\Component\EventDispatcher\Event;
......@@ -44,7 +46,7 @@ use Solarium\Core\Client\Response;
use Solarium\Core\Client\Endpoint;
/**
* PreExecuteRequest event, see Events for details
* PreExecuteRequest event, see Events for details.
*/
class PreExecuteRequest extends Event
{
......@@ -54,17 +56,17 @@ class PreExecuteRequest extends Event
protected $request;
/**
* @var Endpoint
*/
* @var Endpoint
*/
protected $endpoint;
/**
* @var Response
*/
* @var Response
*/
protected $response;
/**
* Event constructor
* Event constructor.
*
* @param Request $request
* @param Endpoint $endpoint
......@@ -76,7 +78,7 @@ class PreExecuteRequest extends Event
}
/**
* Get the endpoint object for this event
* Get the endpoint object for this event.
*
* @return Endpoint
*/
......@@ -86,7 +88,7 @@ class PreExecuteRequest extends Event
}
/**
* Get the request object for this event
* Get the request object for this event.
*
* @return Request
*/
......@@ -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
* @return void
* @param Request $request
*/
public function setRequest($request)
{
......@@ -107,7 +108,7 @@ class PreExecuteRequest extends Event
}
/**
* Get the response object for this event
* Get the response object for this event.
*
* @return Response
*/
......@@ -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
* @return void
* @param Response $response
*/
public function setResponse($response)
{
......
......@@ -30,31 +30,33 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Plugin;
use Solarium\Core\Client\Client;
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
*/
protected $client;
/**
* Initialize
* Initialize.
*
* This method is called when the plugin is registered to a client instance
*
......@@ -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.
* Will be called as soon as $this->client and options have been set.
*
* @return void
*/
protected function initPluginType()
{
}
}
......@@ -30,24 +30,26 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Plugin;
use Solarium\Core\ConfigurableInterface;
use Solarium\Core\Client\Client;
/**
* Interface for plugins
* Interface for plugins.
*/
interface PluginInterface extends ConfigurableInterface
{
/**
* Initialize
* Initialize.
*
* This method is called when the plugin is registered to a client instance
*
......
......@@ -30,44 +30,46 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
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_PHPS = 'phps';
/**
* Helper instance
* Helper instance.
*
* @var Helper
*/
protected $helper;
/**
* Extra query params (e.g. dereferenced params)
* Extra query params (e.g. dereferenced params).
*
* @var 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)
{
......@@ -75,7 +77,7 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Get handler option
* Get handler option.
*
* @return string
*/
......@@ -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
* or a manual require before calling this method. This is your
......@@ -94,8 +96,9 @@ abstract class Query extends Configurable implements QueryInterface
* Also you need to make sure it extends the orginal result class of the
* query or has an identical API.
*
* @param string $classname
* @return self Provides fluent interface
* @param string $classname
*
* @return self Provides fluent interface
*/
public function setResultClass($classname)
{
......@@ -103,7 +106,7 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Get resultclass option
* Get resultclass option.
*
* @return string
*/
......@@ -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
*/
public function setTimeAllowed($value)
......@@ -124,7 +128,7 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Get timeAllowed option
* Get timeAllowed option.
*
* @return int|null
*/
......@@ -134,10 +138,11 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Set omitHeader option
* Set omitHeader option.
*
* @param boolean $value
*
* @param boolean $value
* @return self Provides fluent interface
* @return self Provides fluent interface
*/
public function setOmitHeader($value)
{
......@@ -145,7 +150,7 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Get omitHeader option
* Get omitHeader option.
*
* @return boolean
*/
......@@ -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
*
......@@ -171,14 +176,15 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Add extra params to the request
* Add extra params to the request.
*
* Only intended for internal use, for instance with dereferenced params.
* Therefore the params are limited in functionality. Only add and get
*
* @param string $name
* @param string $value
* @return self Provides fluent interface
* @param string $name
* @param string $value
*
* @return self Provides fluent interface
*/
public function addParam($name, $value)
{
......@@ -188,7 +194,7 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Get extra params
* Get extra params.
*
* @return array
*/
......@@ -198,10 +204,11 @@ abstract class Query extends Configurable implements QueryInterface
}
/**
* Set responsewriter option
* Set responsewriter option.
*
* @param string $value
*
* @param string $value
* @return self Provides fluent interface
* @return self Provides fluent interface
*/
public function setResponseWriter($value)
{
......@@ -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.
*
......
......@@ -30,30 +30,33 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
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
*/
public function build(QueryInterface $query)
{
$request = new Request;
$request = new Request();
$request->setHandler($query->getHandler());
$request->addParam('omitHeader', $query->getOmitHeader());
$request->addParam('timeAllowed', $query->getTimeAllowed());
......@@ -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.
*
* @link http://wiki.apache.org/solr/LocalParams
*
* @param string $value
* @param array $localParams in key => value format
* @param string $value
* @param array $localParams in key => value format
*
* @return string with Solr localparams syntax
*/
public function renderLocalParams($value, $localParams = array())
......@@ -90,29 +95,30 @@ abstract class RequestBuilder implements RequestBuilderInterface
$paramValue = implode($paramValue, ',');
}
$params .= $paramName . '=' . $paramValue . ' ';
$params .= $paramName.'='.$paramValue.' ';
}
if ($params !== '') {
$value = '{!' . trim($params) . '}' . $value;
$value = '{!'.trim($params).'}'.$value;
}
return $value;
}
/**
* Render a boolean attribute
*
* For use in building XML messages
*
* @param string $name
* @param boolean $value
* @return string
*/
* Render a boolean attribute.
*
* For use in building XML messages
*
* @param string $name
* @param boolean $value
*
* @return string
*/
public function boolAttrib($name, $value)
{
if (null !== $value) {
$value = (true == $value) ? 'true' : 'false';
$value = (true === (bool)$value) ? 'true' : 'false';
return $this->attrib($name, $value);
} else {
......@@ -121,18 +127,19 @@ abstract class RequestBuilder implements RequestBuilderInterface
}
/**
* Render an attribute
*
* For use in building XML messages
*
* @param string $name
* @param string $value
* @return string
*/
* Render an attribute.
*
* For use in building XML messages
*
* @param string $name
* @param string $value
*
* @return string
*/
public function attrib($name, $value)
{
if (null !== $value) {
return ' ' . $name . '="' . $value . '"';
return ' '.$name.'="'.$value.'"';
} else {
return '';
}
......
......@@ -30,25 +30,28 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
/**
* Abstract class for response parsers
* Abstract class for response parsers.
*
* 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
*/
public function convertToKeyValueArray($data)
......@@ -56,9 +59,9 @@ abstract class ResponseParser
// key counter to convert values to arrays when keys are re-used
$keys = array();
$dataCount = count($data);
$result = array();
for ($i = 0; $i < count($data); $i += 2) {
for ($i = 0; $i < $dataCount; $i += 2) {
$key = $data[$i];
$value = $data[$i+1];
if (array_key_exists($key, $keys)) {
......@@ -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 $result
*
* @param array $data
* @param array $result
* @return mixed
*/
public function addHeaderInfo($data, $result)
......
This diff is collapsed.
......@@ -30,59 +30,62 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
use Solarium\Core\ConfigurableInterface;
/**
* Query interface
* Query interface.
*/
interface QueryInterface extends ConfigurableInterface
{
/**
* Get type for this query
* Get type for this query.
*
* @return string
*/
public function getType();
/**
* Get the requestbuilder class for this query
* Get the requestbuilder class for this query.
*
* @return RequestBuilderInterface
*/
public function getRequestBuilder();
/**
* Get the response parser class for this query
* Get the response parser class for this query.
*
* @return ResponseParserInterface
*/
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);
/**
* Get handler option
* Get handler option.
*
* @return string
*/
public function getHandler();
/**
* Set resultclass option
* Set resultclass option.
*
* If you set a custom result class it must be available through autoloading
* or a manual require before calling this method. This is your
......@@ -90,39 +93,41 @@ interface QueryInterface extends ConfigurableInterface
*
* Also you need to make sure this class implements the ResultInterface
*
* @param string $classname
* @return self Provides fluent interface
* @param string $classname
*
* @return self Provides fluent interface
*/
public function setResultClass($classname);
/**
* Get resultclass option
* Get resultclass option.
*
* @return string
*/
public function getResultClass();
/**
* Get a helper instance
* Get a helper instance.
*
* @return Helper
*/
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.
* Therefore the params are limited in functionality. Only add and get
*
* @param string $name
* @param string $value
* @return self Provides fluent interface
* @param string $name
* @param string $value
*
* @return self Provides fluent interface
*/
public function addParam($name, $value);
/**
* Get extra params
* Get extra params.
*
* @return array
*/
......
......@@ -30,25 +30,28 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
use Solarium\Core\Client\Request;
/**
* Interface for requestbuilders
* Interface for requestbuilders.
*/
interface RequestBuilderInterface
{
/**
* Build request for a select query
* Build request for a select query.
*
* @param QueryInterface $query
*
* @param QueryInterface $query
* @return Request
*/
public function build(QueryInterface $query);
......
......@@ -30,16 +30,18 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query;
/**
* Interface for response parsers
* Interface for response parsers.
*
* Most {@link Solarium\Client\Adapter} implementations will use HTTP for
* communicating with Solr. While the HTTP part is adapter-specific, the parsing
......@@ -50,11 +52,12 @@ namespace Solarium\Core\Query;
interface ResponseParserInterface
{
/**
* Get a Result object for the given data
* Get a Result object for the given data.
*
* When this method is called the actual response parsing is started.
*
* @param \Solarium\Core\Query\Result\Result $result
* @param \Solarium\Core\Query\Result\Result $result
*
* @return mixed
*/
public function parse($result);
......
......@@ -30,45 +30,45 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query\Result;
use Solarium\Core\Query\ResponseParserInterface;
use Solarium\Exception\UnexpectedValueException;
/**
* QueryType result
* QueryType result.
*/
class QueryType extends Result
{
/**
* Lazy load parsing indicator
* Lazy load parsing indicator.
*
* @var bool
*/
protected $parsed = false;
/**
* Parse response into result objects
* Parse response into result objects.
*
* Only runs once
*
* @throws UnexpectedValueException
* @return void
*/
protected function parseResponse()
{
if (!$this->parsed) {
$responseParser = $this->query->getResponseParser();
if (!$responseParser || !($responseParser instanceof ResponseParserInterface)) {
throw new UnexpectedValueException(
'No responseparser returned by querytype: '. $this->query->getType()
'No responseparser returned by querytype: '.$this->query->getType()
);
}
......@@ -79,10 +79,9 @@ class QueryType extends Result
}
/**
* Map parser data into properties
* Map parser data into properties.
*
* @param array $mapData
* @return void
* @param array $mapData
*/
protected function mapData($mapData)
{
......
......@@ -30,24 +30,26 @@
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
*
* @link http://www.solarium-project.org/
*/
/**
* @namespace
*/
namespace Solarium\Core\Query\Result;
use Solarium\Core\Client\Response;
use Solarium\Core\Query\Query;
use Solarium\Core\Query\AbstractQuery;
/**
* Query result interface
* Query result interface.
*/
interface ResultInterface
{
/**
* Get response object
* Get response object.
*
* This is the raw HTTP response object, not the parsed data!
*
......@@ -56,14 +58,14 @@ interface ResultInterface
public function getResponse();
/**
* Get query instance
* Get query instance.
*
* @return Query
* @return AbstractQuery
*/
public function getQuery();
/**
* Get Solr response data
* Get Solr response data.
*
* Includes a lazy loading mechanism: JSON body data is decoded on first use and then saved for reuse.
*
......
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