diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 95b3cb84..cb7d517a 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -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 @@ -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 diff --git a/DependencyInjection/Compiler/RepositoryPass.php b/DependencyInjection/Compiler/RepositoryPass.php index 4c1c998d..1964f2fd 100644 --- a/DependencyInjection/Compiler/RepositoryPass.php +++ b/DependencyInjection/Compiler/RepositoryPass.php @@ -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']); diff --git a/DependencyInjection/ONGRElasticsearchExtension.php b/DependencyInjection/ONGRElasticsearchExtension.php index 7b65a68c..d2a8e4b5 100644 --- a/DependencyInjection/ONGRElasticsearchExtension.php +++ b/DependencyInjection/ONGRElasticsearchExtension.php @@ -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; @@ -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} */ diff --git a/README.md b/README.md index b5fa3e1d..b3c3c2db 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 1ae092c3..59b0d5c0 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -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%"] diff --git a/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php b/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php index 7e1db459..0ac8cfed 100644 --- a/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php +++ b/Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php @@ -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. @@ -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( diff --git a/composer.json b/composer.json index c4ced674..0bbbd204 100644 --- a/composer.json +++ b/composer.json @@ -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\\": "" },