Skip to content

Commit 850fdbc

Browse files
authored
Merge pull request #1 from bistrosk/8.0
update to PHP 8 & ES 8
2 parents b4c3c89 + 92d816c commit 850fdbc

File tree

235 files changed

+1393
-2419
lines changed

Some content is hidden

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

235 files changed

+1393
-2419
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/vendor/
22
/phpunit.xml
33
/composer.lock
4-
coverage.xml
4+
coverage.xml
5+
.phpunit.cache

.travis.yml

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
sudo: false
22
language: php
33
php:
4-
- 7.1
5-
- 7.2
6-
- 7.3
7-
- 7.4snapshot
8-
matrix:
9-
allow_failures:
10-
- php: 7.4snapshot
4+
- 8.1
115
env:
126
global:
13-
- ES_VERSION=7.4.0 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz
7+
- ES_VERSION=8.9.0 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz
148
install:
159
- wget ${ES_DOWNLOAD_URL}
1610
- tar -xzf elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/make
2+
3+
es::
4+
docker run \
5+
--name elasticsearch \
6+
-p 9200:9200 \
7+
-e discovery.type=single-node \
8+
-e ES_JAVA_OPTS="-Xms1g -Xmx1g"\
9+
-e xpack.security.enabled=false \
10+
-it \
11+
docker.elastic.co/elasticsearch/elasticsearch:8.9.0

README.md

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
# ElasticsearchDSL
22

3-
Introducing Elasticsearch DSL library to provide objective query builder for [Elasticsearch bundle](https://github.com/ongr-io/ElasticsearchBundle) and [elasticsearch-php](https://github.com/elastic/elasticsearch-php) client. You can easily build any Elasticsearch query and transform it to an array.
3+
Introducing Elasticsearch DSL library to provide objective query builder for [elasticsearch-php](https://github.com/elastic/elasticsearch-php) client. You can easily build any Elasticsearch query and transform it to an array.
44

5-
If you need any help, [stack overflow](http://stackoverflow.com/questions/tagged/ongr)
6-
is the preferred and recommended way to ask ONGR support questions.
7-
85
[![Build Status](https://travis-ci.org/ongr-io/ElasticsearchDSL.svg?branch=master)](https://travis-ci.org/ongr-io/ElasticsearchDSL)
96
[![codecov](https://codecov.io/gh/ongr-io/ElasticsearchDSL/branch/master/graph/badge.svg)](https://codecov.io/gh/ongr-io/ElasticsearchDSL)
107
[![Latest Stable Version](https://poser.pugx.org/ongr/elasticsearch-dsl/v/stable)](https://packagist.org/packages/ongr/elasticsearch-dsl)
@@ -18,14 +15,15 @@ If you like this library, help me to develop it by buying a cup of coffee
1815

1916
## Version matrix
2017

21-
| Elasticsearch version | ElasticsearchDSL version |
22-
| --------------------- | --------------------------- |
23-
| >= 7.0 | >= 7.0 |
24-
| >= 6.0, < 7.0 | >= 6.0 |
25-
| >= 5.0, < 6.0 | >= 5.0 |
26-
| >= 2.0, < 5.0 | >= 2.0 (not supported) |
27-
| >= 1.0, < 2.0 | 1.x (not supported) |
28-
| <= 0.90.x | not supported |
18+
| Elasticsearch version | ElasticsearchDSL version |
19+
|-----------------------|--------------------------|
20+
| >= 8.0 | >= 8.0 |
21+
| >= 7.0 | >= 7.0 |
22+
| >= 6.0, < 7.0 | >= 6.0 |
23+
| >= 5.0, < 6.0 | >= 5.0 |
24+
| >= 2.0, < 5.0 | >= 2.0 (not supported) |
25+
| >= 1.0, < 2.0 | 1.x (not supported) |
26+
| <= 0.90.x | not supported |
2927

3028
## Documentation
3129

@@ -38,20 +36,13 @@ If you like this library, help me to develop it by buying a cup of coffee
3836
Install library with [composer](https://getcomposer.org):
3937

4038
```bash
41-
$ composer require ongr/elasticsearch-dsl
39+
$ composer require bistrosk/elasticsearch-dsl
4240
```
4341

4442
> [elasticsearch-php](https://github.com/elastic/elasticsearch-php) client is defined in the composer requirements, no need to install it.
4543
4644
### Search
4745

48-
Elasticsearch DSL was extracted from [Elasticsearch Bundle](https://github.com/ongr-io/ElasticsearchBundle) to provide standalone query dsl for [elasticsearch-php](https://github.com/elastic/elasticsearch-php). Examples how to use it together with [Elasticsearch Bundle](https://github.com/ongr-io/ElasticsearchBundle) can be found in the [Elasticsearch Bundle docs](https://github.com/ongr-io/ElasticsearchBundle/blob/master/Resources/doc/search.md).
49-
50-
If you dont want to use Symfony or Elasticsearch bundle, no worries, you can use it in any project together with [elasticsearch-php](https://github.com/elastic/elasticsearch-php). Here's the example:
51-
52-
If you are using Symfony there is also the [ElasticsearchBundle](https://github.com/ongr-io/ElasticsearchBundle)
53-
which provides full integration with Elasticsearch DSL.
54-
5546
The library is standalone and is not coupled with any framework. You can use it in any PHP project, the only
5647
requirement is composer. Here's the example:
5748

composer.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "ongr/elasticsearch-dsl",
2+
"name": "bistrosk/elasticsearch-dsl",
33
"description": "Elasticsearch DSL library",
44
"type": "library",
55
"homepage": "http://ongr.io",
@@ -11,13 +11,13 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.0",
15-
"symfony/serializer": "^3.0|^4.0",
14+
"php": ">=8.1",
15+
"symfony/serializer": "^6.0",
1616
"paragonie/random_compat": "*"
1717
},
1818
"require-dev": {
19-
"elasticsearch/elasticsearch": "^7.0",
20-
"phpunit/phpunit": "~6.0",
19+
"elasticsearch/elasticsearch": "^8.0",
20+
"phpunit/phpunit": "~10.0",
2121
"squizlabs/php_codesniffer": "^3.0"
2222
},
2323
"suggest": {
@@ -34,9 +34,15 @@
3434
}
3535
},
3636
"minimum-stability": "dev",
37+
"prefer-stable": true,
3738
"extra": {
3839
"branch-alias": {
39-
"dev-master": "7.0-dev"
40+
"dev-master": "8.0-dev"
41+
}
42+
},
43+
"config": {
44+
"allow-plugins": {
45+
"php-http/discovery": true
4046
}
4147
}
4248
}

phpunit.xml.dist

+23-30
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,31 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false"
12-
bootstrap="vendor/autoload.php">
13-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true"
3+
processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
5+
<coverage>
6+
<report>
7+
<text outputFile="php://stdout" showOnlySummary="true"/>
8+
</report>
9+
</coverage>
1410
<testsuites>
1511
<testsuite name="Unit">
1612
<directory>./tests/Unit/</directory>
1713
</testsuite>
18-
<testsuite name="Functional">
19-
<directory>./tests/Functional/</directory>
20-
</testsuite>
21-
<testsuite name="All">
22-
<directory>./tests/</directory>
23-
</testsuite>
14+
<!-- <testsuite name="Functional">-->
15+
<!-- <directory>./tests/Functional/</directory>-->
16+
<!-- </testsuite>-->
17+
<!-- <testsuite name="All">-->
18+
<!-- <directory>./tests/</directory>-->
19+
<!-- </testsuite>-->
2420
</testsuites>
25-
26-
<filter>
27-
<whitelist>
21+
<logging/>
22+
<source>
23+
<include>
2824
<directory>./</directory>
29-
<exclude>
30-
<directory>./tests</directory>
31-
<directory>./vendor</directory>
32-
</exclude>
33-
</whitelist>
34-
</filter>
35-
<logging>
36-
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
37-
</logging>
25+
</include>
26+
<exclude>
27+
<directory>./tests</directory>
28+
<directory>./vendor</directory>
29+
</exclude>
30+
</source>
3831
</phpunit>

src/Aggregation/AbstractAggregation.php

+8-12
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,26 @@ abstract class AbstractAggregation implements NamedBuilderInterface
2929
*/
3030
private $field;
3131

32-
/**
33-
* @var BuilderBag
34-
*/
35-
private $aggregations;
32+
private ?BuilderBag $aggregations = null;
3633

3734
/**
3835
* Abstract supportsNesting method.
3936
*
4037
* @return bool
4138
*/
42-
abstract protected function supportsNesting();
39+
abstract protected function supportsNesting(): bool;
4340

4441
/**
4542
* @return array|\stdClass
4643
*/
47-
abstract protected function getArray();
44+
abstract public function getArray(): array;
4845

4946
/**
5047
* Inner aggregations container init.
5148
*
5249
* @param string $name
5350
*/
54-
public function __construct($name)
51+
public function __construct(string $name)
5552
{
5653
$this->setName($name);
5754
}
@@ -79,13 +76,12 @@ public function getField()
7976
/**
8077
* Adds a sub-aggregation.
8178
*
82-
* @param AbstractAggregation $abstractAggregation
8379
*
8480
* @return $this
8581
*/
8682
public function addAggregation(AbstractAggregation $abstractAggregation)
8783
{
88-
if (!$this->aggregations) {
84+
if (!$this->aggregations instanceof BuilderBag) {
8985
$this->aggregations = $this->createBuilderBag();
9086
}
9187

@@ -101,7 +97,7 @@ public function addAggregation(AbstractAggregation $abstractAggregation)
10197
*/
10298
public function getAggregations()
10399
{
104-
if ($this->aggregations) {
100+
if ($this->aggregations instanceof BuilderBag) {
105101
return $this->aggregations->all();
106102
} else {
107103
return [];
@@ -126,11 +122,11 @@ public function getAggregation($name)
126122
/**
127123
* {@inheritdoc}
128124
*/
129-
public function toArray()
125+
public function toArray(): array
130126
{
131127
$array = $this->getArray();
132128
$result = [
133-
$this->getType() => is_array($array) ? $this->processArray($array) : $array,
129+
$this->getType() => $this->processArray($array),
134130
];
135131

136132
if ($this->supportsNesting()) {

src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
*/
2323
class AdjacencyMatrixAggregation extends AbstractAggregation
2424
{
25-
const FILTERS = 'filters';
25+
final public const FILTERS = 'filters';
2626

2727
use BucketingTrait;
2828

2929
/**
3030
* @var BuilderInterface[]
3131
*/
32-
private $filters = [
32+
private array $filters = [
3333
self::FILTERS => []
3434
];
3535

@@ -39,7 +39,7 @@ class AdjacencyMatrixAggregation extends AbstractAggregation
3939
* @param string $name
4040
* @param BuilderInterface[] $filters
4141
*/
42-
public function __construct($name, $filters = [])
42+
public function __construct(string $name, array $filters = [])
4343
{
4444
parent::__construct($name);
4545

@@ -49,14 +49,9 @@ public function __construct($name, $filters = [])
4949
}
5050

5151
/**
52-
* @param string $name
53-
* @param BuilderInterface $filter
54-
*
5552
* @throws \LogicException
56-
*
57-
* @return self
5853
*/
59-
public function addFilter($name, BuilderInterface $filter)
54+
public function addFilter(string $name, BuilderInterface $filter): static
6055
{
6156
$this->filters[self::FILTERS][$name] = $filter->toArray();
6257

@@ -66,15 +61,15 @@ public function addFilter($name, BuilderInterface $filter)
6661
/**
6762
* {@inheritdoc}
6863
*/
69-
public function getArray()
64+
public function getArray(): array
7065
{
7166
return $this->filters;
7267
}
7368

7469
/**
7570
* {@inheritdoc}
7671
*/
77-
public function getType()
72+
public function getType(): string
7873
{
7974
return 'adjacency_matrix';
8075
}

src/Aggregation/Bucketing/AutoDateHistogramAggregation.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AutoDateHistogramAggregation extends AbstractAggregation
3232
* @param int $buckets
3333
* @param string $format
3434
*/
35-
public function __construct($name, $field, $buckets = null, $format = null)
35+
public function __construct(string $name, $field, $buckets = null, $format = null)
3636
{
3737
parent::__construct($name);
3838

@@ -50,21 +50,19 @@ public function __construct($name, $field, $buckets = null, $format = null)
5050
/**
5151
* {@inheritdoc}
5252
*/
53-
public function getArray()
53+
public function getArray(): array
5454
{
55-
$data = array_filter(
55+
return array_filter(
5656
[
5757
'field' => $this->getField(),
5858
]
5959
);
60-
61-
return $data;
6260
}
6361

6462
/**
6563
* {@inheritdoc}
6664
*/
67-
public function getType()
65+
public function getType(): string
6866
{
6967
return 'auto_date_histogram';
7068
}

0 commit comments

Comments
 (0)