Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ preset: symfony

finder:
path:
- "examples"
- "src"
- "tests"

Expand Down
12 changes: 8 additions & 4 deletions docs/client-and-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Since Solarium 5.2 any [PSR-14](https://www.php-fig.org/psr/psr-14/) compatible
```php
<?php

require_once(__DIR__.'/init.php');
require_once __DIR__.'/init.php';

htmlHeader();

// create a Symfony EventDispatcher instance
Expand Down Expand Up @@ -85,7 +86,8 @@ This is the standard Solarium adapter. It supports the most features (for instan
```php
<?php

require_once(__DIR__.'/init.php');
require_once __DIR__.'/init.php';

htmlHeader();

// create a cURL adapter instance
Expand Down Expand Up @@ -132,7 +134,8 @@ This adapter has no dependencies on other classes or any special PHP extensions
```php
<?php

require_once(__DIR__.'/init.php');
require_once __DIR__.'/init.php';

htmlHeader();

// create an HTTP adapter instance
Expand Down Expand Up @@ -184,7 +187,8 @@ composer require nyholm/psr7
```php
<?php

require_once(__DIR__.'/init.php');
require_once __DIR__.'/init.php';

htmlHeader();

// create a PSR-18 adapter instance
Expand Down
71 changes: 34 additions & 37 deletions docs/customizing-solarium.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ The example code shows how to do this. It also shows how to generate the URI for
```php
<?php

require_once(__DIR__.'/init.php');
require_once __DIR__.'/init.php';

htmlHeader();

// This example shows how to manually execute the query flow.
// By doing this manually you can customize data in between any step (although a plugin might be better for this)
// 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($adapter, $eventDispatcher, $config);

Expand All @@ -48,7 +48,7 @@ $request = $client->createRequest($query);

// you can now use the request object for getting an uri (e.g. to use in your own code)
// or you could modify the request object
echo 'Request URI: ' . $request->getUri() . '<br/>';
echo 'Request URI: '.$request->getUri().'<br/>';

// you can still execute the request using the client and get a 'raw' response object
$response = $client->executeRequest($request);
Expand All @@ -61,7 +61,6 @@ echo 'NumFound: '.$result->getNumFound();

// show documents using the resultset iterator
foreach ($result as $document) {

echo '<hr/><table>';

// the documents are also iterable, to get all fields
Expand All @@ -71,7 +70,7 @@ foreach ($result as $document) {
$value = implode(', ', $value);
}

echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
}

echo '</table>';
Expand Down Expand Up @@ -100,54 +99,55 @@ This example shows all available events and how to use the events to create a ve
```php
<?php

require_once(__DIR__.'/init.php');
use Solarium\Core\Event\Events;
use Solarium\Core\Event\PreExecuteRequest;

require_once __DIR__.'/init.php';

// this very simple plugin shows a timing for each event and display some request debug info
class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
{
protected float $start;
protected array $output = array();
protected array $output = [];

// This method is called when the plugin is registered with the client.
protected function initPluginType(): void
{
$this->start = microtime(true);

$dispatcher = $this->client->getEventDispatcher();
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
$dispatcher->addListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
$dispatcher->addListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
$dispatcher->addListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
$dispatcher->addListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
$dispatcher->addListener(Events::POST_EXECUTE, array($this, 'postExecute'));
$dispatcher->addListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
$dispatcher->addListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
$dispatcher->addListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
$dispatcher->addListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
$dispatcher->addListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
$dispatcher->addListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
$dispatcher->addListener(Events::POST_EXECUTE, [$this, 'postExecute']);
$dispatcher->addListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
$dispatcher->addListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
}

// This method is called if the plugin is removed from the client.
public function deinitPlugin(): void
{
$dispatcher = $this->client->getEventDispatcher();
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
$dispatcher->removeListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
$dispatcher->removeListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
$dispatcher->removeListener(Events::POST_EXECUTE, array($this, 'postExecute'));
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
$dispatcher->removeListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
$dispatcher->removeListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
$dispatcher->removeListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
$dispatcher->removeListener(Events::POST_EXECUTE, [$this, 'postExecute']);
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
$dispatcher->removeListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
}

protected function timer(string $event): void
{
$time = round(microtime(true) - $this->start, 5);
$this->output[] = '['.$time.'] ' . $event;
$this->output[] = '['.$time.'] '.$event;
}

public function display(): void
Expand All @@ -174,7 +174,7 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
// this dummy param will be visible in the debug output but will also be used in the actual Solr request
$event->getRequest()->addParam('dummyparam', 'dummyvalue');

$this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
$this->output[] = 'Request URI: '.$event->getRequest()->getUri();
}

public function postExecuteRequest(): void
Expand Down Expand Up @@ -213,7 +213,6 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
}
}


htmlHeader();

// create a client instance and register the plugin
Expand All @@ -227,15 +226,14 @@ $resultset = $client->select($query);

echo 'NumFound: '.$resultset->getNumFound();
foreach ($resultset as $document) {

echo '<hr/><table>';

foreach ($document as $field => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}

echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
}

echo '</table>';
Expand All @@ -253,11 +251,12 @@ The second example shows how to replace the built-in select querytype with a cus
```php
<?php

require_once(__DIR__.'/init.php');
use Solarium\Client;
use Solarium\Core\Plugin\AbstractPlugin;
use Solarium\QueryType\Select\Query\Query as Select;

require_once __DIR__.'/init.php';

// This is a custom query class that could have some customized logic
class MyQuery extends Select
{
Expand All @@ -276,7 +275,6 @@ class QueryCustomizer extends AbstractPlugin
}
}


htmlHeader();

// create a client instance and register the plugin
Expand All @@ -287,21 +285,20 @@ $client->registerPlugin('querycustomizer', 'QueryCustomizer');
$query = $client->createSelect();

// check the query class, it should be our custom query class
echo 'Query class: ' . get_class($query) . '<br/>';
echo 'Query class: '.get_class($query).'<br/>';

// execute the query and display the results
$resultset = $client->select($query);
echo 'NumFound: '.$resultset->getNumFound();
foreach ($resultset as $document) {

echo '<hr/><table>';

foreach ($document as $field => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}

echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
echo '<tr><th>'.$field.'</th><td>'.$value.'</td></tr>';
}

echo '</table>';
Expand Down
Loading
Loading