Skip to content

Commit

Permalink
adjust documentation for Client and Adapter changes in 5.2 (#773)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher authored Apr 3, 2020
1 parent dcfe394 commit 9208b61
Show file tree
Hide file tree
Showing 48 changed files with 246 additions and 103 deletions.
66 changes: 32 additions & 34 deletions docs/client-and-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ The adapters are the actual implementations for communication with Solr. They ha

### Authentication

The Http, Curl and Pecl adapter support authentication. To use this set the authentication on the request object using the setAuthentication() method. For the ZendHttp adapter you set the authentication using the ZendHttp api or config.
The Http and Curl adapter support authentication. To use this set the authentication on the request object using the setAuthentication() method.

### HTTP request timeout handling

Setting a timeout for the HTTP request handling is the responsibility of the Adapters.
The two build-in Adapters `Curl` and `Http` are implementing `TimeoutAwareInterface` and expose a `setTimeout`
method to give you control over the timeout value that is used.

If you are using any other adapter like the build-in `Psr18Adapter` you need to take care of handling
the timeouts yourself and configure the HTTP client properly that is used to perform the requests.

Endpoints
---------
Expand All @@ -43,13 +52,7 @@ As this is the default adapter you don't need any settings or API calls to use i
The curl adapter support the use of a proxy. Use the adapter option `proxy` to enable this.


Guzzle adapter
==============

todo


HttpAdapter
Http adapter
===========

This adapter has no dependencies on other classes or any special PHP extensions as it uses basic PHP streams. This makes it a safe choice, but it has no extra options. If you need detailed control over your request or response you should probably use another adapter, but for most standard cases it will do just fine.
Expand All @@ -64,10 +67,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);

// set the adapter to curl
$client->setAdapter('Solarium\Core\Client\Adapter\Http');
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Http(),
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get a select query instance
$query = $client->createSelect();
Expand Down Expand Up @@ -100,34 +104,29 @@ htmlFooter();

```

Zend2Http adapter
================

The ZendHttp adapter makes use of the Zend\_Http component in Zend Framework (version 3). So to use this adapter you need to have ZF available. By using Zend\_Http all the features of this component are available:
Psr-18 adapter
============

- multiple adapter implementations
- keepalive
- cookies / sessions
- redirection support
- http authentication
- and much more, see the [http://framework.zend.com/manual/en/zend.http.html Zend Http manual](http://framework.zend.com/manual/en/zend.http.html_Zend_Http_manual "wikilink")
Since Solarium 5.2 there is also a `Psr18Adapter` which can be used with any PSR-18 compliant HTTP client.

The base functionality is the same as the default adapter. The only difference is that this adapter allows you to set Zend\_Http options and also offers access to the Zend\_Http instance.
Example:

```php
<?php

require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);

// set the adapter to zendhttp and get a zendhttp client instance reference
$client->setAdapter('Solarium\Core\Client\Adapter\Zend2Http');
use Nyholm\Psr7\Factory\Psr17Factory;
use Solarium\Client;
use Http\Adapter\Guzzle6\Client as GuzzlePsrClient;
use Solarium\Core\Client\Adapter\Psr18Adapter;
use Symfony\Component\EventDispatcher\EventDispatcher;

htmlFooter();
$adapter = new Psr18Adapter(
new GuzzlePsrClient(),
new Psr17Factory(),
new Psr17Factory()
);

$client = new Client($adapter, new EventDispatcher());
```

Custom adapter
Expand All @@ -138,6 +137,5 @@ You can also use a custom adapter, with these steps:
- Create your custom adapter class. It should implement Solarium\\Core\\Client\\Adapter\\AdapterInterface.
- You can take a look at the existing implementations as an example.
- Make sure your class is available to Solarium, by including it manually or through autoloading.
- Call the 'setAdapter' method on your Solarium client instance with your own adapters' classname as argument (or use the 'adapter' config setting)
- Inject your custom adapter instance into the constructor of the Client
- Now use Solarium as you normally would, all communication to Solr will be done using your adapter. The adapter class will only be instantiated on the first communication to Solr, not directly after calling 'setAdapter' (lazy loading)

9 changes: 7 additions & 2 deletions docs/customizing-solarium.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ htmlHeader();
// And you can use only a part of the flow. You could for instance use the query object and request builder,
// but execute the request in your own code.

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// create a select query instance
$query = $client->createSelect();
Expand Down Expand Up @@ -200,7 +201,11 @@ htmlHeader();

// create a client instance and register the plugin
$plugin = new BasicDebug();
$client = new Solarium\Client($config);

// ...

// create a client instance
$client = new Solarium\Client($adapter, $eventDispatcher, $config);;
$client->registerPlugin('debugger', $plugin);

// execute a select query and display the results
Expand Down
10 changes: 7 additions & 3 deletions docs/documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Example usage
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance
$query = $client->createQuery($client::QUERY_SELECT);
Expand Down Expand Up @@ -144,8 +146,10 @@ Example usage
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get an update query instance
$update = $client->createUpdate();
Expand Down Expand Up @@ -185,4 +189,4 @@ You can easily use your own 'document' types, for instance to directly map Solr

- make sure the class is available (already loaded or can be autoloaded)
- set the 'documentclass' option of your query to your own classname
- the class must implement the same interface as the original document class.
- the class must implement the same interface as the original document class.
38 changes: 31 additions & 7 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ See [<https://packagist.org>](https://packagist.org) for other packages.
```json
{
"require": {
"solarium/solarium": "~5.0.0"
"solarium/solarium": "^5.2"
}
}
```
Expand All @@ -55,7 +55,11 @@ htmlHeader();
echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// create a ping query
$ping = $client->createPing();
Expand Down Expand Up @@ -147,7 +151,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get a select query instance
$query = $client->createQuery($client::QUERY_SELECT);
Expand Down Expand Up @@ -193,7 +201,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get a select query instance
$query = $client->createSelect();
Expand Down Expand Up @@ -242,7 +254,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get an update query instance
$update = $client->createUpdate();
Expand Down Expand Up @@ -271,7 +287,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get an update query instance
$update = $client->createUpdate();
Expand Down Expand Up @@ -304,7 +324,11 @@ require(__DIR__.'/init.php');
htmlHeader();

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client(
new Solarium\Core\Client\Adapter\Curl(), // or any other adapter implementing AdapterInterface
new Symfony\Component\EventDispatcher\EventDispatcher(),
$config
);

// get an update query instance
$update = $client->createUpdate();
Expand Down
8 changes: 6 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ require(__DIR__.'/init.php');

htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// enable the plugin and get a query instance
$filter = $client->getPlugin('minimumscorefilter');
Expand Down Expand Up @@ -464,8 +466,10 @@ require(__DIR__.'/init.php');

htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance
$query = $client->createSelect();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/analysis-query/analysis-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get an analysis document query
$query = $client->createAnalysisDocument();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/analysis-query/analysis-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get an analysis document query
$query = $client->createAnalysisField();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/extract-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get an extract query instance and add settings
$query = $client->createExtract();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/ping-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ htmlHeader();
// check solarium version available
echo 'Solarium library version: ' . Solarium\Client::VERSION . ' - ';

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// create a ping query
$ping = $client->createPing();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/query-helper/escaping.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ An example of term escaping in use for a query that would fail without escaping:
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance
$query = $client->createSelect();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/query-helper/placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance
$query = $client->createSelect();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/query-helper/query-helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance and a query helper instance
$query = $client->createSelect();
Expand Down
4 changes: 3 additions & 1 deletion docs/queries/realtimeget-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ Example
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get an update query instance
$update = $client->createUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ Examples
require(__DIR__.'/init.php');
htmlHeader();

// ...

// create a client instance
$client = new Solarium\Client($config);
$client = new Solarium\Client($adapter, $eventDispatcher, $config);

// get a select query instance
$query = $client->createSelect();
Expand Down
Loading

0 comments on commit 9208b61

Please sign in to comment.