Skip to content

Commit

Permalink
Add support for doctrine/annotations 2.0 and remove requirement to do…
Browse files Browse the repository at this point in the history
…ctrine/cache (#32)
  • Loading branch information
Prokyonn authored Dec 11, 2024
2 parents 095a3a4 + 5318ddb commit 0fbb9b6
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 35 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/test-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: '7.2'
elasticsearch-version: '5.6.14'
lint: false
symfony-version: '^2.8'
elasticsearch-package-constraint: '^5.0'
env:
SYMFONY_PHPUNIT_VERSION: '7.5'

- php-version: '7.2'
elasticsearch-version: '5.6.14'
lint: false
Expand Down Expand Up @@ -128,6 +120,12 @@ jobs:
restore-keys: |
${{ runner.os }}-composer-
- name: Composer require
if: ${{ matrix.symfony-version == '^4.4' }}
# symfony 4.4 not compatible with doctrine/annotations 2.0: https://github.com/symfony/symfony/issues/48717#issuecomment-1359164836
run: |
composer require --no-update doctrine/annotations:^1.10
- name: Install dependencies
run: |
composer validate
Expand Down
14 changes: 14 additions & 0 deletions DependencyInjection/Compiler/RepositoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,21 @@ public function process(ContainerBuilder $container)
{
$managers = $container->getParameter('es.managers');

$removeContainerBuildId = false;
if (!$container->hasParameter('container.build_id')) {
// the 'container.build_id' is required for `es.cache_engine` system cache which normally can not
// be constructor inside a compiler pass. This is a workaround to make it work.
// see also:
// - https://github.com/symfony/symfony/blob/52a92926f7fed15cdff399c6921100a10e0d6f61/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L389
// - https://github.com/symfony/symfony/blob/52a92926f7fed15cdff399c6921100a10e0d6f61/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2322
$container->setParameter('container.build_id', hash('crc32', 'Abc123' . time()));
$removeContainerBuildId = true;
}

$collector = $container->get('es.metadata_collector');
if ($removeContainerBuildId) {
$container->getParameterBag()->remove('container.build_id');
}

foreach ($managers as $managerName => $manager) {
$mappings = $collector->getMappings($manager['mappings']);
Expand Down
21 changes: 20 additions & 1 deletion DependencyInjection/ONGRElasticsearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
Expand All @@ -24,8 +25,26 @@
/**
* This is the class that loads and manages bundle configuration.
*/
class ONGRElasticsearchExtension extends Extension
class ONGRElasticsearchExtension extends Extension implements PrependExtensionInterface
{
public function prepend(ContainerBuilder $container)
{
if ($container->hasExtension('framework')) {
$container->prependExtensionConfig(
'framework',
[
'cache' => [
'pools' => [
'es.cache_engine' => [
'adapter' => 'cache.system',
],
],
],
]
);
}
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
This is a fork of the [ongr/elasticsearch-bundle](https://github.com/ongr-io/elasticsearchbundle).
With some basic changes to support wider range of Symfony Versions.

| Version | Supported Elasticsearch Version | Supported Symfony Version |
|-----------|---------------------------------|--------------------------------------|
| `5.x` | `^7.0, ^6.0, ^5.0` | `^7.0, ^6.0, ^5.0, ^4.0, ^3.4, ^2.8` |
| `1.x` | `^1.0, ^2.0` | `^3.0, ^2.7` |
| Version | Supported Elasticsearch Version | Supported Symfony Version | Supported Doctrine Annotations Version |
|-------------|---------------------------------|--------------------------------------|----------------------------------------|
| `5.5` | `^7.0, ^6.0, ^5.0` | `^6.0, ^5.0, ^4.0, ^3.4` | `^1.13, ^2.0` |
| `5.0 - 5.4` | `^7.0, ^6.0, ^5.0` | `^7.0, ^6.0, ^5.0, ^4.0, ^3.4, ^2.8` | `^1.0` |
| `1.x` | `^1.0, ^2.0` | `^3.0, ^2.7` | `^1.0` |

## Documentation

Expand Down
7 changes: 1 addition & 6 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ services:
class: 'ONGR\ElasticsearchBundle\Service\IndexSuffixFinder'
public: true

es.cache_engine:
class: 'Doctrine\Common\Cache\FilesystemCache'
public: true
arguments: ["%kernel.cache_dir%/ongr/elasticsearch", ".ongr.data"]

es.annotations.cached_reader:
class: 'Doctrine\Common\Annotations\CachedReader'
class: 'Doctrine\Common\Annotations\PsrCachedReader'
public: true
arguments: ["@es.annotations.reader", "@es.cache_engine", "%kernel.debug%"]

Expand Down
4 changes: 4 additions & 0 deletions Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

/**
* Unit tests for MappingPass.
Expand Down Expand Up @@ -85,6 +86,9 @@ function ($parameter) use ($managers) {
)
);

$containerMock->expects($this->exactly(1))->method('getParameterBag')
->willReturn(new ParameterBag());

$containerMock->expects($this->once())->method('get')->with($this->anything())
->will(
$this->returnCallback(
Expand Down
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
],
"require": {
"php": "^7.2|^8.0",
"symfony/framework-bundle": "^2.8|^3.0|^4|^5|^6|^7",
"symfony/console": "^2.8|^3.0|^4|^5|^6|^7",
"symfony/stopwatch": "^2.8|^3.0|^4|^5|^6|^7",
"symfony/templating": "^2.8|^3.0|^4|^5|^6|^7",
"symfony/asset": "^2.8|^3.0|^4|^5|^6|^7",
"doctrine/annotations": "^1.10",
"symfony/framework-bundle": "^3.4|^4|^5|^6|^7",
"symfony/console": "^3.4|^4|^5|^6|^7",
"symfony/stopwatch": "^3.4|^4|^5|^6|^7",
"symfony/templating": "^3.4|^4|^5|^6|^7",
"symfony/asset": "^3.4|^4|^5|^6|^7",
"doctrine/annotations": "^1.13 || ^2.0",
"doctrine/inflector": "^1.0 || ^2.0",
"doctrine/cache": "~1.4",
"doctrine/collections": "^1.4|^2.0",
"doctrine/collections": "~1.4",
"monolog/monolog": "^1.10 || ^2.0 || ^3.0",
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1|^6.2.0.1|^7.2.0.1",
"symfony/event-dispatcher": "^2.8|^3.0|^4|^5|^6|^7"
"symfony/event-dispatcher": "^3.4|^4|^5|^6|^7"
},
"require-dev": {
"mikey179/vfsstream": "~1.4",
"squizlabs/php_codesniffer": "^2.0|^3.0",
"symfony/browser-kit" : "^2.8|^3.4|^4|^5|^6|^7",
"symfony/expression-language" : "^2.8|^3.4|^4|^5|^6|^7",
"symfony/twig-bundle": "^2.8|^3.4|^4|^5|^6|^7",
"symfony/serializer": "^2.8|^3.4|^4|^5|^6|^7",
"symfony/yaml": "^2.8|^3.4|^4|^5|^6|^7",
"symfony/browser-kit" : "^3.4|^4|^5|^6|^7",
"symfony/expression-language" : "^3.4|^4|^5|^6|^7",
"symfony/twig-bundle": "^3.4|^4|^5|^6|^7",
"symfony/serializer": "^3.4|^4|^5|^6|^7",
"symfony/yaml": "^3.4|^4|^5|^6|^7",
"symfony/phpunit-bridge": "^5.1|^6|^7",
"symfony/dependency-injection": "^2.8|^3.4|^4|^5|^6|^7",
"symfony/validator": "^2.8|^3.4|^4|^5|^6|^7",
"symfony/options-resolver": "^2.8|^3.4|^4|^5|^6|^7"
"symfony/dependency-injection": "^3.4|^4|^5|^6|^7",
"symfony/validator": "^3.4|^4|^5|^6|^7",
"symfony/options-resolver": "^3.4|^4|^5|^6|^7"
},
"autoload": {
"psr-4": { "ONGR\\ElasticsearchBundle\\": "" },
Expand Down

0 comments on commit 0fbb9b6

Please sign in to comment.