Skip to content

Commit 0fbb9b6

Browse files
authored
Add support for doctrine/annotations 2.0 and remove requirement to doctrine/cache (#32)
2 parents 095a3a4 + 5318ddb commit 0fbb9b6

File tree

7 files changed

+66
-35
lines changed

7 files changed

+66
-35
lines changed

.github/workflows/test-application.yaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
include:
20-
- php-version: '7.2'
21-
elasticsearch-version: '5.6.14'
22-
lint: false
23-
symfony-version: '^2.8'
24-
elasticsearch-package-constraint: '^5.0'
25-
env:
26-
SYMFONY_PHPUNIT_VERSION: '7.5'
27-
2820
- php-version: '7.2'
2921
elasticsearch-version: '5.6.14'
3022
lint: false
@@ -128,6 +120,12 @@ jobs:
128120
restore-keys: |
129121
${{ runner.os }}-composer-
130122
123+
- name: Composer require
124+
if: ${{ matrix.symfony-version == '^4.4' }}
125+
# symfony 4.4 not compatible with doctrine/annotations 2.0: https://github.com/symfony/symfony/issues/48717#issuecomment-1359164836
126+
run: |
127+
composer require --no-update doctrine/annotations:^1.10
128+
131129
- name: Install dependencies
132130
run: |
133131
composer validate

DependencyInjection/Compiler/RepositoryPass.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,21 @@ public function process(ContainerBuilder $container)
2929
{
3030
$managers = $container->getParameter('es.managers');
3131

32+
$removeContainerBuildId = false;
33+
if (!$container->hasParameter('container.build_id')) {
34+
// the 'container.build_id' is required for `es.cache_engine` system cache which normally can not
35+
// be constructor inside a compiler pass. This is a workaround to make it work.
36+
// see also:
37+
// - https://github.com/symfony/symfony/blob/52a92926f7fed15cdff399c6921100a10e0d6f61/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php#L389
38+
// - https://github.com/symfony/symfony/blob/52a92926f7fed15cdff399c6921100a10e0d6f61/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2322
39+
$container->setParameter('container.build_id', hash('crc32', 'Abc123' . time()));
40+
$removeContainerBuildId = true;
41+
}
42+
3243
$collector = $container->get('es.metadata_collector');
44+
if ($removeContainerBuildId) {
45+
$container->getParameterBag()->remove('container.build_id');
46+
}
3347

3448
foreach ($managers as $managerName => $manager) {
3549
$mappings = $collector->getMappings($manager['mappings']);

DependencyInjection/ONGRElasticsearchExtension.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Config\FileLocator;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
1718
use Symfony\Component\DependencyInjection\Loader;
1819
use Symfony\Component\DependencyInjection\Definition;
1920
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
@@ -24,8 +25,26 @@
2425
/**
2526
* This is the class that loads and manages bundle configuration.
2627
*/
27-
class ONGRElasticsearchExtension extends Extension
28+
class ONGRElasticsearchExtension extends Extension implements PrependExtensionInterface
2829
{
30+
public function prepend(ContainerBuilder $container)
31+
{
32+
if ($container->hasExtension('framework')) {
33+
$container->prependExtensionConfig(
34+
'framework',
35+
[
36+
'cache' => [
37+
'pools' => [
38+
'es.cache_engine' => [
39+
'adapter' => 'cache.system',
40+
],
41+
],
42+
],
43+
]
44+
);
45+
}
46+
}
47+
2948
/**
3049
* {@inheritdoc}
3150
*/

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
This is a fork of the [ongr/elasticsearch-bundle](https://github.com/ongr-io/elasticsearchbundle).
44
With some basic changes to support wider range of Symfony Versions.
55

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

1112
## Documentation
1213

Resources/config/services.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@ services:
1515
class: 'ONGR\ElasticsearchBundle\Service\IndexSuffixFinder'
1616
public: true
1717

18-
es.cache_engine:
19-
class: 'Doctrine\Common\Cache\FilesystemCache'
20-
public: true
21-
arguments: ["%kernel.cache_dir%/ongr/elasticsearch", ".ongr.data"]
22-
2318
es.annotations.cached_reader:
24-
class: 'Doctrine\Common\Annotations\CachedReader'
19+
class: 'Doctrine\Common\Annotations\PsrCachedReader'
2520
public: true
2621
arguments: ["@es.annotations.reader", "@es.cache_engine", "%kernel.debug%"]
2722

Tests/Unit/DependencyInjection/Compiler/MappingPassTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPUnit\Framework\TestCase;
1717
use Symfony\Component\DependencyInjection\Alias;
1818
use Symfony\Component\DependencyInjection\Definition;
19+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1920

2021
/**
2122
* Unit tests for MappingPass.
@@ -85,6 +86,9 @@ function ($parameter) use ($managers) {
8586
)
8687
);
8788

89+
$containerMock->expects($this->exactly(1))->method('getParameterBag')
90+
->willReturn(new ParameterBag());
91+
8892
$containerMock->expects($this->once())->method('get')->with($this->anything())
8993
->will(
9094
$this->returnCallback(

composer.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
],
1717
"require": {
1818
"php": "^7.2|^8.0",
19-
"symfony/framework-bundle": "^2.8|^3.0|^4|^5|^6|^7",
20-
"symfony/console": "^2.8|^3.0|^4|^5|^6|^7",
21-
"symfony/stopwatch": "^2.8|^3.0|^4|^5|^6|^7",
22-
"symfony/templating": "^2.8|^3.0|^4|^5|^6|^7",
23-
"symfony/asset": "^2.8|^3.0|^4|^5|^6|^7",
24-
"doctrine/annotations": "^1.10",
19+
"symfony/framework-bundle": "^3.4|^4|^5|^6|^7",
20+
"symfony/console": "^3.4|^4|^5|^6|^7",
21+
"symfony/stopwatch": "^3.4|^4|^5|^6|^7",
22+
"symfony/templating": "^3.4|^4|^5|^6|^7",
23+
"symfony/asset": "^3.4|^4|^5|^6|^7",
24+
"doctrine/annotations": "^1.13 || ^2.0",
2525
"doctrine/inflector": "^1.0 || ^2.0",
26-
"doctrine/cache": "~1.4",
2726
"doctrine/collections": "^1.4|^2.0",
27+
"doctrine/collections": "~1.4",
2828
"monolog/monolog": "^1.10 || ^2.0 || ^3.0",
2929
"handcraftedinthealps/elasticsearch-dsl": "^5.0.7.1|^6.2.0.1|^7.2.0.1",
30-
"symfony/event-dispatcher": "^2.8|^3.0|^4|^5|^6|^7"
30+
"symfony/event-dispatcher": "^3.4|^4|^5|^6|^7"
3131
},
3232
"require-dev": {
3333
"mikey179/vfsstream": "~1.4",
3434
"squizlabs/php_codesniffer": "^2.0|^3.0",
35-
"symfony/browser-kit" : "^2.8|^3.4|^4|^5|^6|^7",
36-
"symfony/expression-language" : "^2.8|^3.4|^4|^5|^6|^7",
37-
"symfony/twig-bundle": "^2.8|^3.4|^4|^5|^6|^7",
38-
"symfony/serializer": "^2.8|^3.4|^4|^5|^6|^7",
39-
"symfony/yaml": "^2.8|^3.4|^4|^5|^6|^7",
35+
"symfony/browser-kit" : "^3.4|^4|^5|^6|^7",
36+
"symfony/expression-language" : "^3.4|^4|^5|^6|^7",
37+
"symfony/twig-bundle": "^3.4|^4|^5|^6|^7",
38+
"symfony/serializer": "^3.4|^4|^5|^6|^7",
39+
"symfony/yaml": "^3.4|^4|^5|^6|^7",
4040
"symfony/phpunit-bridge": "^5.1|^6|^7",
41-
"symfony/dependency-injection": "^2.8|^3.4|^4|^5|^6|^7",
42-
"symfony/validator": "^2.8|^3.4|^4|^5|^6|^7",
43-
"symfony/options-resolver": "^2.8|^3.4|^4|^5|^6|^7"
41+
"symfony/dependency-injection": "^3.4|^4|^5|^6|^7",
42+
"symfony/validator": "^3.4|^4|^5|^6|^7",
43+
"symfony/options-resolver": "^3.4|^4|^5|^6|^7"
4444
},
4545
"autoload": {
4646
"psr-4": { "ONGR\\ElasticsearchBundle\\": "" },

0 commit comments

Comments
 (0)