@@ -28,15 +28,15 @@ The example code shows how to do this. It also shows how to generate the URI for
2828``` php
2929<?php
3030
31- require_once(__DIR__.'/init.php');
31+ require_once __DIR__.'/init.php';
32+
3233htmlHeader();
3334
3435// This example shows how to manually execute the query flow.
3536// By doing this manually you can customize data in between any step (although a plugin might be better for this)
3637// And you can use only a part of the flow. You could for instance use the query object and request builder,
3738// but execute the request in your own code.
3839
39-
4040// create a client instance
4141$client = new Solarium\Client($adapter, $eventDispatcher, $config);
4242
@@ -48,7 +48,7 @@ $request = $client->createRequest($query);
4848
4949// you can now use the request object for getting an uri (e.g. to use in your own code)
5050// or you could modify the request object
51- echo 'Request URI: ' . $request->getUri() . '<br />';
51+ echo 'Request URI: '. $request->getUri(). '<br />';
5252
5353// you can still execute the request using the client and get a 'raw' response object
5454$response = $client->executeRequest($request);
@@ -61,7 +61,6 @@ echo 'NumFound: '.$result->getNumFound();
6161
6262// show documents using the resultset iterator
6363foreach ($result as $document) {
64-
6564 echo '<hr /><table >';
6665
6766 // the documents are also iterable, to get all fields
@@ -71,7 +70,7 @@ foreach ($result as $document) {
7170 $value = implode(', ', $value);
7271 }
7372
74- echo '<tr ><th >' . $field . '</th ><td >' . $value . '</td ></tr >';
73+ echo '<tr ><th >'. $field. '</th ><td >'. $value. '</td ></tr >';
7574 }
7675
7776 echo '</table >';
@@ -100,54 +99,55 @@ This example shows all available events and how to use the events to create a ve
10099``` php
101100<?php
102101
103- require_once(__DIR__.'/init.php');
104102use Solarium\Core\Event\Events;
105103use Solarium\Core\Event\PreExecuteRequest;
106104
105+ require_once __DIR__.'/init.php';
106+
107107// this very simple plugin shows a timing for each event and display some request debug info
108108class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
109109{
110110 protected float $start;
111- protected array $output = array() ;
111+ protected array $output = [] ;
112112
113113 // This method is called when the plugin is registered with the client.
114114 protected function initPluginType(): void
115115 {
116116 $this->start = microtime(true);
117117
118118 $dispatcher = $this->client->getEventDispatcher();
119- $dispatcher->addListener(Events::PRE_CREATE_REQUEST, array( $this, 'preCreateRequest') );
120- $dispatcher->addListener(Events::POST_CREATE_REQUEST, array( $this, 'postCreateRequest') );
121- $dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array( $this, 'preExecuteRequest') );
122- $dispatcher->addListener(Events::POST_EXECUTE_REQUEST, array( $this, 'postExecuteRequest') );
123- $dispatcher->addListener(Events::PRE_CREATE_RESULT, array( $this, 'preCreateResult') );
124- $dispatcher->addListener(Events::POST_CREATE_RESULT, array( $this, 'postCreateResult') );
125- $dispatcher->addListener(Events::PRE_EXECUTE, array( $this, 'preExecute') );
126- $dispatcher->addListener(Events::POST_EXECUTE, array( $this, 'postExecute') );
127- $dispatcher->addListener(Events::PRE_CREATE_QUERY, array( $this, 'preCreateQuery') );
128- $dispatcher->addListener(Events::POST_CREATE_QUERY, array( $this, 'postCreateQuery') );
119+ $dispatcher->addListener(Events::PRE_CREATE_REQUEST, [ $this, 'preCreateRequest'] );
120+ $dispatcher->addListener(Events::POST_CREATE_REQUEST, [ $this, 'postCreateRequest'] );
121+ $dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, [ $this, 'preExecuteRequest'] );
122+ $dispatcher->addListener(Events::POST_EXECUTE_REQUEST, [ $this, 'postExecuteRequest'] );
123+ $dispatcher->addListener(Events::PRE_CREATE_RESULT, [ $this, 'preCreateResult'] );
124+ $dispatcher->addListener(Events::POST_CREATE_RESULT, [ $this, 'postCreateResult'] );
125+ $dispatcher->addListener(Events::PRE_EXECUTE, [ $this, 'preExecute'] );
126+ $dispatcher->addListener(Events::POST_EXECUTE, [ $this, 'postExecute'] );
127+ $dispatcher->addListener(Events::PRE_CREATE_QUERY, [ $this, 'preCreateQuery'] );
128+ $dispatcher->addListener(Events::POST_CREATE_QUERY, [ $this, 'postCreateQuery'] );
129129 }
130130
131131 // This method is called if the plugin is removed from the client.
132132 public function deinitPlugin(): void
133133 {
134134 $dispatcher = $this->client->getEventDispatcher();
135- $dispatcher->removeListener(Events::PRE_CREATE_REQUEST, array( $this, 'preCreateRequest') );
136- $dispatcher->removeListener(Events::POST_CREATE_REQUEST, array( $this, 'postCreateRequest') );
137- $dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, array( $this, 'preExecuteRequest') );
138- $dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, array( $this, 'postExecuteRequest') );
139- $dispatcher->removeListener(Events::PRE_CREATE_RESULT, array( $this, 'preCreateResult') );
140- $dispatcher->removeListener(Events::POST_CREATE_RESULT, array( $this, 'postCreateResult') );
141- $dispatcher->removeListener(Events::PRE_EXECUTE, array( $this, 'preExecute') );
142- $dispatcher->removeListener(Events::POST_EXECUTE, array( $this, 'postExecute') );
143- $dispatcher->removeListener(Events::PRE_CREATE_QUERY, array( $this, 'preCreateQuery') );
144- $dispatcher->removeListener(Events::POST_CREATE_QUERY, array( $this, 'postCreateQuery') );
135+ $dispatcher->removeListener(Events::PRE_CREATE_REQUEST, [ $this, 'preCreateRequest'] );
136+ $dispatcher->removeListener(Events::POST_CREATE_REQUEST, [ $this, 'postCreateRequest'] );
137+ $dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, [ $this, 'preExecuteRequest'] );
138+ $dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, [ $this, 'postExecuteRequest'] );
139+ $dispatcher->removeListener(Events::PRE_CREATE_RESULT, [ $this, 'preCreateResult'] );
140+ $dispatcher->removeListener(Events::POST_CREATE_RESULT, [ $this, 'postCreateResult'] );
141+ $dispatcher->removeListener(Events::PRE_EXECUTE, [ $this, 'preExecute'] );
142+ $dispatcher->removeListener(Events::POST_EXECUTE, [ $this, 'postExecute'] );
143+ $dispatcher->removeListener(Events::PRE_CREATE_QUERY, [ $this, 'preCreateQuery'] );
144+ $dispatcher->removeListener(Events::POST_CREATE_QUERY, [ $this, 'postCreateQuery'] );
145145 }
146146
147147 protected function timer(string $event): void
148148 {
149149 $time = round(microtime(true) - $this->start, 5);
150- $this->output[] = '['.$time.'] ' . $event;
150+ $this->output[] = '['.$time.'] '. $event;
151151 }
152152
153153 public function display(): void
@@ -174,7 +174,7 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
174174 // this dummy param will be visible in the debug output but will also be used in the actual Solr request
175175 $event->getRequest()->addParam('dummyparam', 'dummyvalue');
176176
177- $this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
177+ $this->output[] = 'Request URI: '. $event->getRequest()->getUri();
178178 }
179179
180180 public function postExecuteRequest(): void
@@ -213,7 +213,6 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
213213 }
214214}
215215
216-
217216htmlHeader();
218217
219218// create a client instance and register the plugin
@@ -227,15 +226,14 @@ $resultset = $client->select($query);
227226
228227echo 'NumFound: '.$resultset->getNumFound();
229228foreach ($resultset as $document) {
230-
231229 echo '<hr /><table >';
232230
233231 foreach ($document as $field => $value) {
234232 if (is_array($value)) {
235233 $value = implode(', ', $value);
236234 }
237235
238- echo '<tr ><th >' . $field . '</th ><td >' . $value . '</td ></tr >';
236+ echo '<tr ><th >'. $field. '</th ><td >'. $value. '</td ></tr >';
239237 }
240238
241239 echo '</table >';
@@ -253,11 +251,12 @@ The second example shows how to replace the built-in select querytype with a cus
253251``` php
254252<?php
255253
256- require_once(__DIR__.'/init.php');
257254use Solarium\Client;
258255use Solarium\Core\Plugin\AbstractPlugin;
259256use Solarium\QueryType\Select\Query\Query as Select;
260257
258+ require_once __DIR__.'/init.php';
259+
261260// This is a custom query class that could have some customized logic
262261class MyQuery extends Select
263262{
@@ -276,7 +275,6 @@ class QueryCustomizer extends AbstractPlugin
276275 }
277276}
278277
279-
280278htmlHeader();
281279
282280// create a client instance and register the plugin
@@ -287,21 +285,20 @@ $client->registerPlugin('querycustomizer', 'QueryCustomizer');
287285$query = $client->createSelect();
288286
289287// check the query class, it should be our custom query class
290- echo 'Query class: ' . get_class($query) . '<br />';
288+ echo 'Query class: '. get_class($query). '<br />';
291289
292290// execute the query and display the results
293291$resultset = $client->select($query);
294292echo 'NumFound: '.$resultset->getNumFound();
295293foreach ($resultset as $document) {
296-
297294 echo '<hr /><table >';
298295
299296 foreach ($document as $field => $value) {
300297 if (is_array($value)) {
301298 $value = implode(', ', $value);
302299 }
303300
304- echo '<tr ><th >' . $field . '</th ><td >' . $value . '</td ></tr >';
301+ echo '<tr ><th >'. $field. '</th ><td >'. $value. '</td ></tr >';
305302 }
306303
307304 echo '</table >';
0 commit comments