Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to PHP 8 & ES 8 #1

Merged
merged 1 commit into from
Aug 3, 2023
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
/phpunit.xml
/composer.lock
coverage.xml
coverage.xml
.phpunit.cache
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
sudo: false
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4snapshot
matrix:
allow_failures:
- php: 7.4snapshot
- 8.1
env:
global:
- ES_VERSION=7.4.0 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz
- ES_VERSION=8.9.0 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz
install:
- wget ${ES_DOWNLOAD_URL}
- tar -xzf elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/make

es::
docker run \
--name elasticsearch \
-p 9200:9200 \
-e discovery.type=single-node \
-e ES_JAVA_OPTS="-Xms1g -Xmx1g"\
-e xpack.security.enabled=false \
-it \
docker.elastic.co/elasticsearch/elasticsearch:8.9.0
31 changes: 11 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# ElasticsearchDSL

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.
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.

If you need any help, [stack overflow](http://stackoverflow.com/questions/tagged/ongr)
is the preferred and recommended way to ask ONGR support questions.

[![Build Status](https://travis-ci.org/ongr-io/ElasticsearchDSL.svg?branch=master)](https://travis-ci.org/ongr-io/ElasticsearchDSL)
[![codecov](https://codecov.io/gh/ongr-io/ElasticsearchDSL/branch/master/graph/badge.svg)](https://codecov.io/gh/ongr-io/ElasticsearchDSL)
[![Latest Stable Version](https://poser.pugx.org/ongr/elasticsearch-dsl/v/stable)](https://packagist.org/packages/ongr/elasticsearch-dsl)
Expand All @@ -18,14 +15,15 @@ If you like this library, help me to develop it by buying a cup of coffee

## Version matrix

| Elasticsearch version | ElasticsearchDSL version |
| --------------------- | --------------------------- |
| >= 7.0 | >= 7.0 |
| >= 6.0, < 7.0 | >= 6.0 |
| >= 5.0, < 6.0 | >= 5.0 |
| >= 2.0, < 5.0 | >= 2.0 (not supported) |
| >= 1.0, < 2.0 | 1.x (not supported) |
| <= 0.90.x | not supported |
| Elasticsearch version | ElasticsearchDSL version |
|-----------------------|--------------------------|
| >= 8.0 | >= 8.0 |
| >= 7.0 | >= 7.0 |
| >= 6.0, < 7.0 | >= 6.0 |
| >= 5.0, < 6.0 | >= 5.0 |
| >= 2.0, < 5.0 | >= 2.0 (not supported) |
| >= 1.0, < 2.0 | 1.x (not supported) |
| <= 0.90.x | not supported |

## Documentation

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

```bash
$ composer require ongr/elasticsearch-dsl
$ composer require bistrosk/elasticsearch-dsl
```

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

### Search

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).

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:

If you are using Symfony there is also the [ElasticsearchBundle](https://github.com/ongr-io/ElasticsearchBundle)
which provides full integration with Elasticsearch DSL.

The library is standalone and is not coupled with any framework. You can use it in any PHP project, the only
requirement is composer. Here's the example:

Expand Down
18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ongr/elasticsearch-dsl",
"name": "bistrosk/elasticsearch-dsl",
"description": "Elasticsearch DSL library",
"type": "library",
"homepage": "http://ongr.io",
Expand All @@ -11,13 +11,13 @@
}
],
"require": {
"php": "^7.0",
"symfony/serializer": "^3.0|^4.0",
"php": ">=8.1",
"symfony/serializer": "^6.0",
"paragonie/random_compat": "*"
},
"require-dev": {
"elasticsearch/elasticsearch": "^7.0",
"phpunit/phpunit": "~6.0",
"elasticsearch/elasticsearch": "^8.0",
"phpunit/phpunit": "~10.0",
"squizlabs/php_codesniffer": "^3.0"
},
"suggest": {
Expand All @@ -34,9 +34,15 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "7.0-dev"
"dev-master": "8.0-dev"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
}
}
53 changes: 23 additions & 30 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php">

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true"
processIsolation="false" stopOnFailure="false" bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>./tests/Unit/</directory>
</testsuite>
<testsuite name="Functional">
<directory>./tests/Functional/</directory>
</testsuite>
<testsuite name="All">
<directory>./tests/</directory>
</testsuite>
<!-- <testsuite name="Functional">-->
<!-- <directory>./tests/Functional/</directory>-->
<!-- </testsuite>-->
<!-- <testsuite name="All">-->
<!-- <directory>./tests/</directory>-->
<!-- </testsuite>-->
</testsuites>

<filter>
<whitelist>
<logging/>
<source>
<include>
<directory>./</directory>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
</logging>
</include>
<exclude>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</source>
</phpunit>
20 changes: 8 additions & 12 deletions src/Aggregation/AbstractAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,26 @@ abstract class AbstractAggregation implements NamedBuilderInterface
*/
private $field;

/**
* @var BuilderBag
*/
private $aggregations;
private ?BuilderBag $aggregations = null;

/**
* Abstract supportsNesting method.
*
* @return bool
*/
abstract protected function supportsNesting();
abstract protected function supportsNesting(): bool;

/**
* @return array|\stdClass
*/
abstract protected function getArray();
abstract public function getArray(): array;

/**
* Inner aggregations container init.
*
* @param string $name
*/
public function __construct($name)
public function __construct(string $name)
{
$this->setName($name);
}
Expand Down Expand Up @@ -79,13 +76,12 @@ public function getField()
/**
* Adds a sub-aggregation.
*
* @param AbstractAggregation $abstractAggregation
*
* @return $this
*/
public function addAggregation(AbstractAggregation $abstractAggregation)
{
if (!$this->aggregations) {
if (!$this->aggregations instanceof BuilderBag) {
$this->aggregations = $this->createBuilderBag();
}

Expand All @@ -101,7 +97,7 @@ public function addAggregation(AbstractAggregation $abstractAggregation)
*/
public function getAggregations()
{
if ($this->aggregations) {
if ($this->aggregations instanceof BuilderBag) {
return $this->aggregations->all();
} else {
return [];
Expand All @@ -126,11 +122,11 @@ public function getAggregation($name)
/**
* {@inheritdoc}
*/
public function toArray()
public function toArray(): array
{
$array = $this->getArray();
$result = [
$this->getType() => is_array($array) ? $this->processArray($array) : $array,
$this->getType() => $this->processArray($array),
];

if ($this->supportsNesting()) {
Expand Down
17 changes: 6 additions & 11 deletions src/Aggregation/Bucketing/AdjacencyMatrixAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
*/
class AdjacencyMatrixAggregation extends AbstractAggregation
{
const FILTERS = 'filters';
final public const FILTERS = 'filters';

use BucketingTrait;

/**
* @var BuilderInterface[]
*/
private $filters = [
private array $filters = [
self::FILTERS => []
];

Expand All @@ -39,7 +39,7 @@ class AdjacencyMatrixAggregation extends AbstractAggregation
* @param string $name
* @param BuilderInterface[] $filters
*/
public function __construct($name, $filters = [])
public function __construct(string $name, array $filters = [])
{
parent::__construct($name);

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

/**
* @param string $name
* @param BuilderInterface $filter
*
* @throws \LogicException
*
* @return self
*/
public function addFilter($name, BuilderInterface $filter)
public function addFilter(string $name, BuilderInterface $filter): static
{
$this->filters[self::FILTERS][$name] = $filter->toArray();

Expand All @@ -66,15 +61,15 @@ public function addFilter($name, BuilderInterface $filter)
/**
* {@inheritdoc}
*/
public function getArray()
public function getArray(): array
{
return $this->filters;
}

/**
* {@inheritdoc}
*/
public function getType()
public function getType(): string
{
return 'adjacency_matrix';
}
Expand Down
10 changes: 4 additions & 6 deletions src/Aggregation/Bucketing/AutoDateHistogramAggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AutoDateHistogramAggregation extends AbstractAggregation
* @param int $buckets
* @param string $format
*/
public function __construct($name, $field, $buckets = null, $format = null)
public function __construct(string $name, $field, $buckets = null, $format = null)
{
parent::__construct($name);

Expand All @@ -50,21 +50,19 @@ public function __construct($name, $field, $buckets = null, $format = null)
/**
* {@inheritdoc}
*/
public function getArray()
public function getArray(): array
{
$data = array_filter(
return array_filter(
[
'field' => $this->getField(),
]
);

return $data;
}

/**
* {@inheritdoc}
*/
public function getType()
public function getType(): string
{
return 'auto_date_histogram';
}
Expand Down
Loading