Skip to content

Commit 93d0f39

Browse files
Typed properties
1 parent af81c91 commit 93d0f39

File tree

589 files changed

+2259
-4159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

589 files changed

+2259
-4159
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Added `void` return type to `Solarium\Core\Plugin\PluginInterface::deinitPlugin()` method signature
1818
- Added `void` return type to `Solarium\Core\Plugin\AbstractPlugin::initPluginType()` method signature
1919
- Changed return type of some Facets methods from `self`to `static`
20+
- Replaced class property type hints with type declarations
21+
- Added union type declarations to method signatures
2022

2123
### Removed
2224
- Solarium\Component\Result\Stats\FacetValue::getFacets(), always returned `null`

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ composer require solarium/solarium
3232

3333
When upgrading from an earlier version, you should be aware of a number of pitfalls.
3434

35+
* [Pitfalls when upgrading to 7.0.0](https://solarium.readthedocs.io/en/stable/getting-started/#pitfalls-when-upgrading-to-700)
3536
* [Pitfall when upgrading to 6.3.6](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-636)
3637
* [Pitfall when upgrading to 6.3.2](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-632)
3738
* [Pitfall when upgrading to 6.3](https://solarium.readthedocs.io/en/stable/getting-started/#pitfall-when-upgrading-to-63)

docs/client-and-adapters.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ The cURL adapter supports the use of a proxy. Use `$adapter->setProxy($proxy)` t
107107
You can extend the cURL adapter and override the `createHandle()` method to set additional options you require for the cURL transfer.
108108

109109
```php
110+
use Solarium\Core\Client\Endpoint;
111+
use Solarium\Core\Client\Request;
112+
110113
class MyAdapter extends Solarium\Core\Client\Adapter\Curl
111114
{
112-
public function createHandle($request, $endpoint)
115+
public function createHandle(Request $request, Endpoint $endpoint): \CurlHandle
113116
{
114117
$handle = parent::createHandle($request, $endpoint);
115118

@@ -151,9 +154,12 @@ The HTTP adapter supports the use of a proxy. Use `$adapter->setProxy($proxy)` t
151154
You can extend the HTTP adapter and override the `createContext()` method to set additional options you require for the stream.
152155

153156
```php
157+
use Solarium\Core\Client\Endpoint;
158+
use Solarium\Core\Client\Request;
159+
154160
class MyAdapter extends Solarium\Core\Client\Adapter\Http
155161
{
156-
public function createContext($request, $endpoint)
162+
public function createContext(Request $request, Endpoint $endpoint)
157163
{
158164
$context = parent::createContext($request, $endpoint);
159165

docs/customizing-solarium.md

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,67 +106,67 @@ use Solarium\Core\Event\Events;
106106
// this very simple plugin shows a timing for each event and display some request debug info
107107
class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
108108
{
109-
protected $start;
110-
protected $output = array();
109+
protected float $start;
110+
protected array $output = [];
111111

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

117117
$dispatcher = $this->client->getEventDispatcher();
118-
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
119-
$dispatcher->addListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
120-
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
121-
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
122-
$dispatcher->addListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
123-
$dispatcher->addListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
124-
$dispatcher->addListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
125-
$dispatcher->addListener(Events::POST_EXECUTE, array($this, 'postExecute'));
126-
$dispatcher->addListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
127-
$dispatcher->addListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
118+
$dispatcher->addListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
119+
$dispatcher->addListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
120+
$dispatcher->addListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
121+
$dispatcher->addListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
122+
$dispatcher->addListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
123+
$dispatcher->addListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
124+
$dispatcher->addListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
125+
$dispatcher->addListener(Events::POST_EXECUTE, [$this, 'postExecute']);
126+
$dispatcher->addListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
127+
$dispatcher->addListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
128128
}
129129

130130
// This method is called if the plugin is removed from the client.
131131
public function deinitPlugin(): void
132132
{
133133
$dispatcher = $this->client->getEventDispatcher();
134-
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, array($this, 'preCreateRequest'));
135-
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, array($this, 'postCreateRequest'));
136-
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, array($this, 'preExecuteRequest'));
137-
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, array($this, 'postExecuteRequest'));
138-
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, array($this, 'preCreateResult'));
139-
$dispatcher->removeListener(Events::POST_CREATE_RESULT, array($this, 'postCreateResult'));
140-
$dispatcher->removeListener(Events::PRE_EXECUTE, array($this, 'preExecute'));
141-
$dispatcher->removeListener(Events::POST_EXECUTE, array($this, 'postExecute'));
142-
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, array($this, 'preCreateQuery'));
143-
$dispatcher->removeListener(Events::POST_CREATE_QUERY, array($this, 'postCreateQuery'));
134+
$dispatcher->removeListener(Events::PRE_CREATE_REQUEST, [$this, 'preCreateRequest']);
135+
$dispatcher->removeListener(Events::POST_CREATE_REQUEST, [$this, 'postCreateRequest']);
136+
$dispatcher->removeListener(Events::PRE_EXECUTE_REQUEST, [$this, 'preExecuteRequest']);
137+
$dispatcher->removeListener(Events::POST_EXECUTE_REQUEST, [$this, 'postExecuteRequest']);
138+
$dispatcher->removeListener(Events::PRE_CREATE_RESULT, [$this, 'preCreateResult']);
139+
$dispatcher->removeListener(Events::POST_CREATE_RESULT, [$this, 'postCreateResult']);
140+
$dispatcher->removeListener(Events::PRE_EXECUTE, [$this, 'preExecute']);
141+
$dispatcher->removeListener(Events::POST_EXECUTE, [$this, 'postExecute']);
142+
$dispatcher->removeListener(Events::PRE_CREATE_QUERY, [$this, 'preCreateQuery']);
143+
$dispatcher->removeListener(Events::POST_CREATE_QUERY, [$this, 'postCreateQuery']);
144144
}
145145

146-
protected function timer($event)
146+
protected function timer($event): void
147147
{
148148
$time = round(microtime(true) - $this->start, 5);
149149
$this->output[] = '['.$time.'] ' . $event;
150150
}
151151

152-
public function display()
152+
public function display(): void
153153
{
154154
echo implode('<br/>', $this->output);
155155
}
156156

157-
public function preCreateRequest()
157+
public function preCreateRequest(): void
158158
{
159159
$this->timer('preCreateRequest');
160160
}
161161

162-
public function postCreateRequest()
162+
public function postCreateRequest(): void
163163
{
164164
$this->timer('postCreateRequest');
165165
}
166166

167167
// This method uses the available param(s) (see plugin abstract class).
168168
// You can access or modify data this way.
169-
public function preExecuteRequest($event)
169+
public function preExecuteRequest($event): void
170170
{
171171
$this->timer('preExecuteRequest');
172172

@@ -176,37 +176,37 @@ class BasicDebug extends Solarium\Core\Plugin\AbstractPlugin
176176
$this->output[] = 'Request URI: ' . $event->getRequest()->getUri();
177177
}
178178

179-
public function postExecuteRequest()
179+
public function postExecuteRequest(): void
180180
{
181181
$this->timer('postExecuteRequest');
182182
}
183183

184-
public function preCreateResult()
184+
public function preCreateResult(): void
185185
{
186186
$this->timer('preCreateResult');
187187
}
188188

189-
public function postCreateResult()
189+
public function postCreateResult(): void
190190
{
191191
$this->timer('postCreateResult');
192192
}
193193

194-
public function preExecute()
194+
public function preExecute(): void
195195
{
196196
$this->timer('preExecute');
197197
}
198198

199-
public function postExecute()
199+
public function postExecute(): void
200200
{
201201
$this->timer('postExecute');
202202
}
203203

204-
public function preCreateQuery()
204+
public function preCreateQuery(): void
205205
{
206206
$this->timer('preCreateResult');
207207
}
208208

209-
public function postCreateQuery()
209+
public function postCreateQuery(): void
210210
{
211211
$this->timer('postCreateResult');
212212
}
@@ -266,7 +266,7 @@ class MyQuery extends Select
266266
// this very simple plugin that modifies the default querytype mapping
267267
class QueryCustomizer extends AbstractPlugin
268268
{
269-
public function initPlugin($client, $options)
269+
public function initPlugin($client, $options): void
270270
{
271271
$client->registerQueryType(
272272
Client::QUERY_SELECT,

docs/documents.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ $doc2->name = 'testdoc-2';
112112
$doc2->price = 340;
113113

114114
// add the documents and a commit command to the update query
115-
$update->addDocuments(array($doc1, $doc2));
115+
$update->addDocuments([$doc1, $doc2]);
116116
$update->addCommit();
117117

118118
// this executes the query and returns the result
@@ -158,36 +158,36 @@ $update = $client->createUpdate();
158158
$doc1 = $update->createDocument();
159159
$doc1->id = 123;
160160
$doc1->name = 'testdoc-1';
161-
$doc1->childdocs = array(
162-
array(
161+
$doc1->childdocs = [
162+
[
163163
'id' => 1230,
164164
'name' => 'childdoc-1-1',
165165
'price' => 465,
166-
),
167-
array(
166+
],
167+
[
168168
'id' => 1231,
169169
'name' => 'childdoc-1-2',
170170
'price' => 545,
171-
),
172-
);
171+
],
172+
];
173173

174174
// and a second one where child documents are added one by one
175175
$doc2 = $update->createDocument();
176176
$doc2->setField('id', 124);
177177
$doc2->setField('name', 'testdoc-2');
178-
$doc2->addField('childdocs', array(
178+
$doc2->addField('childdocs', [
179179
'id' => 1240,
180180
'name' => 'childdoc-2-1',
181181
'price' => 360,
182-
));
183-
$doc2->addField('childdocs', array(
182+
]);
183+
$doc2->addField('childdocs', [
184184
'id' => 1241,
185185
'name' => 'childdoc-2-2',
186186
'price' => 398,
187-
));
187+
]);
188188

189189
// add the documents and a commit command to the update query
190-
$update->addDocuments(array($doc1, $doc2));
190+
$update->addDocuments([$doc1, $doc2]);
191191
$update->addCommit();
192192

193193
// this executes the query and returns the result

docs/getting-started.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,25 @@ Upgrading
9090

9191
When upgrading from an earlier version, you should be aware of a number of pitfalls.
9292

93-
### Pitfall when upgrading to 6.3.8
93+
### Pitfalls when upgrading to 7.0.0
94+
95+
Solarium 7.0.0 added type declarations throughout the codebase for:
96+
- class properties
97+
- union types in method signatures
98+
- `void` return types
9499

95100
Plugins extending from `Solarium\Core\Plugin\AbstractPlugin` must add `void` return types to the signatures for
96101
the following methods (when defined):
97102
- `initPlugin()`
98103
- `deinitPlugin()`
99104
- `initPluginType()`
100105

106+
Any other classes extending from the codebase will run into fatal errors if they violate PHP's
107+
[variance](https://www.php.net/manual/en/language.oop5.variance.php) rules. Inherited properties
108+
must add an invariant type declaration. Inherited methods that didn't declare a return type must
109+
add one that's covariant. Method parameters don't need to have a type declaration, but if they
110+
do have one it must be contravariant.
111+
101112
### Pitfall when upgrading to 6.3.6
102113

103114
Using a config object is no longer supported. You have to convert it to an array before passing
@@ -289,9 +300,9 @@ The `$config` array has the following contents:
289300
```php
290301
<?php
291302

292-
$config = array(
293-
'endpoint' => array(
294-
'localhost' => array(
303+
$config = [
304+
'endpoint' => [
305+
'localhost' => [
295306
'host' => '127.0.0.1',
296307
'port' => 8983,
297308
'path' => '/',
@@ -300,9 +311,9 @@ $config = array(
300311
// 'collection' => 'techproducts',
301312
// Set the `hostContext` for the Solr web application if it's not the default 'solr':
302313
// 'context' => 'solr',
303-
)
304-
)
305-
);
314+
],
315+
],
316+
];
306317
```
307318

308319
### Selecting documents
@@ -491,7 +502,7 @@ $doc2->name = 'testdoc-2';
491502
$doc2->price = 340;
492503

493504
// add the documents and a commit command to the update query
494-
$update->addDocuments(array($doc1, $doc2));
505+
$update->addDocuments([$doc1, $doc2]);
495506
$update->addCommit();
496507

497508
// this executes the query and returns the result

docs/plugins.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ $buffer->setBufferSize(10); // this is quite low, in most cases you can use a mu
6666
// also register an event hook to display what is happening
6767
$client->getEventDispatcher()->addListener(
6868
Events::PRE_FLUSH,
69-
function (PreFlushEvent $event) {
69+
function (PreFlushEvent $event): void {
7070
echo 'Flushing buffer (' . count($event->getBuffer()) . ' docs)<br/>';
7171
}
7272
);
@@ -75,11 +75,11 @@ $client->getEventDispatcher()->addListener(
7575
for ($i=1; $i<=25; $i++) {
7676

7777
// create a new document with dummy data and add it to the buffer
78-
$data = array(
78+
$data = [
7979
'id' => 'test_'.$i,
8080
'name' => 'test for buffered add',
8181
'price' => $i,
82-
);
82+
];
8383
$buffer->createDocument($data);
8484

8585
// alternatively you could create document instances yourself and use the addDocument(s) method
@@ -162,7 +162,7 @@ $buffer->setBufferSize(10); // this is quite low, in most cases you can use a mu
162162
// also register an event hook to display what is happening
163163
$client->getEventDispatcher()->addListener(
164164
Events::PRE_FLUSH,
165-
function (PreFlushEvent $event) {
165+
function (PreFlushEvent $event): void {
166166
echo 'Flushing buffer (' . count($event->getBuffer()) . ' deletes)<br/>';
167167
}
168168
);
@@ -222,13 +222,13 @@ $customizer = $client->getPlugin('customizerequest');
222222

223223
// add a persistent HTTP header (using array input values)
224224
$customizer->createCustomization(
225-
array(
225+
[
226226
'key' => 'auth',
227227
'type' => 'header',
228228
'name' => 'X-my-auth',
229229
'value' => 'mypassword',
230-
'persistent' => true
231-
)
230+
'persistent' => true,
231+
]
232232
);
233233

234234
// add a persistent GET param (using fluent interface)
@@ -402,7 +402,7 @@ $client = new Solarium\Client($adapter, $eventDispatcher, $config);
402402
$filter = $client->getPlugin('minimumscorefilter');
403403
$query = $client->createQuery($filter::QUERY_TYPE);
404404
$query->setQuery('a');
405-
$query->setFields(array('id'));
405+
$query->setFields(['id']);
406406
$query->setFilterRatio(.5);
407407
$query->setFilterMode($query::FILTER_MODE_MARK);
408408

@@ -508,13 +508,13 @@ $parallel = $client->getPlugin('parallelexecution');
508508
// If you don't have to plugin the example still works, just without the delay.
509509
$customizer = $client->getPlugin('customizerequest');
510510
$customizer->createCustomization(
511-
array(
511+
[
512512
'key' => 'delay',
513513
'type' => 'param',
514514
'name' => 'delay',
515515
'value' => '500',
516-
'persistent' => true
517-
)
516+
'persistent' => true,
517+
]
518518
);
519519

520520
// create two queries to execute
@@ -697,7 +697,7 @@ $client = new Solarium\Client($adapter, $eventDispatcher, $config);
697697

698698
// get a select query instance
699699
$query = $client->createSelect();
700-
$query->setFields(array('id'));
700+
$query->setFields(['id']);
701701

702702
// cursor functionality can be used for efficient deep paging (since Solr 4.7)
703703
$query->setCursorMark('*');

0 commit comments

Comments
 (0)