Skip to content

Commit

Permalink
Merge pull request #8 from smoench/remove-symfony
Browse files Browse the repository at this point in the history
remove symfony dependency
  • Loading branch information
smoench authored Jun 29, 2023
2 parents ea032b3 + 3e04cbe commit e501821
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 197 deletions.
22 changes: 2 additions & 20 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,30 +73,13 @@ jobs:
run: vendor/bin/phpstan analyse

unit-test:
name: 'Run unit tests with php ${{ matrix.php-version }} with symfony ${{ matrix.symfony-version}}'
name: 'Run unit tests with php ${{ matrix.php-version }}'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
include:
- php-version: '8.0'
symfony-version: '5.4.*'

- php-version: '8.1'
symfony-version: '5.4.*'

- php-version: '8.1'
symfony-version: '6.0.*'

- php-version: '8.1'
symfony-version: '6.1.*'

- php-version: '8.1'
symfony-version: '6.2.*'

- php-version: '8.2'
symfony-version: '6.2.*'
php-version: [ '8.0', '8.1', '8.2' ]

steps:
- name: Checkout project
Expand Down Expand Up @@ -124,7 +107,6 @@ jobs:
- name: Install dependencies
run: |
composer validate --strict
composer require --no-update symfony/serializer:${{ matrix.symfony-version }}
composer install --no-interaction --prefer-dist
- name: Run tests
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
This is a fork of the [ongr/elasticsearch-dsl](https://github.com/ongr-io/elasticsearchbundle).
With some basic changes to support wider range of Symfony Versions.

| Version | Supported OpenSearch Version | Supported Symfony Version |
|---------|------------------------------|------------------------------------|
| `1.x` | `^1.2`, `^2.0` | `5.4.*`, `6.0.*`, `6.1.*`, `6.2.*` |
| Version | Supported OpenSearch Version |
|---------|------------------------------|
| `1.x` | `^1.2`, `^2.0` |

## Documentation

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
],
"require": {
"php": "8.0.* || 8.1.* || 8.2.*",
"symfony/serializer": "5.4.* || 6.0.* || 6.1.* || 6.2.*",
"opensearch-project/opensearch-php": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "1.8.11",
"phpstan/phpstan-phpunit": "1.1.3",
"phpunit/phpunit": "^9.6",
"phpstan/phpstan": "1.10.21",
"phpstan/phpstan-phpunit": "1.3.13",
"rector/rector": "^0.14.5",
"symplify/easy-coding-standard": "^11.1"
"symplify/easy-coding-standard": "^11.5.0"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 1 addition & 8 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
use OpenSearchDSL\SearchEndpoint\SearchEndpointInterface;
use OpenSearchDSL\SearchEndpoint\SortEndpoint;
use OpenSearchDSL\SearchEndpoint\SuggestEndpoint;
use OpenSearchDSL\Serializer\Normalizer\CustomReferencedNormalizer;
use OpenSearchDSL\Serializer\OrderedSerializer;
use stdClass;
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;

/**
* Search object that can be executed by a manager.
Expand Down Expand Up @@ -156,12 +154,7 @@ public function __wakeup()
private function initializeSerializer(): void
{
if (self::$serializer === null) {
self::$serializer = new OrderedSerializer(
[
new CustomReferencedNormalizer(),
new CustomNormalizer(),
]
);
self::$serializer = new OrderedSerializer();
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/SearchEndpoint/AggregationsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace OpenSearchDSL\SearchEndpoint;

use OpenSearchDSL\Aggregation\AbstractAggregation;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search aggregations dsl endpoint.
Expand All @@ -24,11 +23,8 @@ class AggregationsEndpoint extends AbstractSearchEndpoint
*/
public const NAME = 'aggregations';

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
$output = [];
if ($this->getAll() !== []) {
/** @var AbstractAggregation $aggregation */
Expand Down
10 changes: 3 additions & 7 deletions src/SearchEndpoint/HighlightEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use OpenSearchDSL\BuilderInterface;
use OverflowException;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search highlight dsl endpoint.
Expand All @@ -32,16 +31,13 @@ class HighlightEndpoint extends AbstractSearchEndpoint
*/
private ?string $key = null;

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
if ($this->highlight !== null) {
return $this->highlight->toArray();
}

return false;
return null;
}

public function add(BuilderInterface $builder, ?string $key = null): string
Expand Down
8 changes: 2 additions & 6 deletions src/SearchEndpoint/InnerHitsEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace OpenSearchDSL\SearchEndpoint;

use OpenSearchDSL\InnerHit\NestedInnerHit;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search inner hits dsl endpoint.
Expand All @@ -24,11 +23,8 @@ class InnerHitsEndpoint extends AbstractSearchEndpoint
*/
public const NAME = 'inner_hits';

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
$output = [];
if ($this->getAll() !== []) {
/** @var NestedInnerHit $innerHit */
Expand Down
15 changes: 3 additions & 12 deletions src/SearchEndpoint/PostFilterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace OpenSearchDSL\SearchEndpoint;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search post filter dsl endpoint.
*/
Expand All @@ -23,16 +21,9 @@ class PostFilterEndpoint extends QueryEndpoint
*/
public const NAME = 'post_filter';

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
if ($this->getBool() === null) {
return false;
}

return $this->getBool()->toArray();
public function normalize(): ?array
{
return $this->getBool()?->toArray();
}

public function getOrder(): int
Expand Down
14 changes: 3 additions & 11 deletions src/SearchEndpoint/QueryEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use OpenSearchDSL\BuilderInterface;
use OpenSearchDSL\Query\Compound\BoolQuery;
use OpenSearchDSL\Serializer\Normalizer\OrderedNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search query dsl endpoint.
Expand All @@ -30,23 +29,16 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI

private bool $filtersSet = false;

public function normalize(
NormalizerInterface $normalizer,
string $format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
if (! $this->filtersSet && $this->hasReference('filter_query')) {
/** @var BuilderInterface $filter */
$filter = $this->getReference('filter_query');
$this->addToBool($filter, BoolQuery::FILTER);
$this->filtersSet = true;
}

if ($this->bool === null) {
return false;
}

return $this->bool->toArray();
return $this->bool?->toArray();
}

public function add(BuilderInterface $builder, ?string $key = null): string
Expand Down
3 changes: 1 addition & 2 deletions src/SearchEndpoint/SearchEndpointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

use OpenSearchDSL\BuilderInterface;
use OpenSearchDSL\Query\Compound\BoolQuery;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;

/**
* Interface used to define search endpoint.
*/
interface SearchEndpointInterface extends NormalizableInterface
interface SearchEndpointInterface
{
/**
* Adds builder to search endpoint.
Expand Down
9 changes: 2 additions & 7 deletions src/SearchEndpoint/SortEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace OpenSearchDSL\SearchEndpoint;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search sort dsl endpoint.
*/
Expand All @@ -23,11 +21,8 @@ class SortEndpoint extends AbstractSearchEndpoint
*/
public const NAME = 'sort';

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
$output = [];

foreach ($this->getAll() as $sort) {
Expand Down
9 changes: 2 additions & 7 deletions src/SearchEndpoint/SuggestEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace OpenSearchDSL\SearchEndpoint;

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

/**
* Search suggest dsl endpoint.
*/
Expand All @@ -23,11 +21,8 @@ class SuggestEndpoint extends AbstractSearchEndpoint
*/
public const NAME = 'suggest';

public function normalize(
NormalizerInterface $normalizer,
$format = null,
array $context = []
): array|string|int|float|bool {
public function normalize(): ?array
{
$output = [];
if ($this->getAll() !== []) {
foreach ($this->getAll() as $suggest) {
Expand Down
5 changes: 3 additions & 2 deletions src/Serializer/Normalizer/AbstractNormalizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
namespace OpenSearchDSL\Serializer\Normalizer;

use OpenSearchDSL\ParametersTrait;
use Symfony\Component\Serializer\Normalizer\NormalizableInterface;

/**
* Custom abstract normalizer which can save references for other objects.
*/
abstract class AbstractNormalizable implements NormalizableInterface
abstract class AbstractNormalizable
{
use ParametersTrait {
ParametersTrait::hasParameter as hasReference;
Expand All @@ -27,4 +26,6 @@ abstract class AbstractNormalizable implements NormalizableInterface
ParametersTrait::removeParameter as removeReference;
ParametersTrait::setParameters as setReferences;
}

abstract public function normalize(): ?array;
}
39 changes: 0 additions & 39 deletions src/Serializer/Normalizer/CustomReferencedNormalizer.php

This file was deleted.

Loading

0 comments on commit e501821

Please sign in to comment.