Skip to content

Commit 69e7c46

Browse files
Add support for doctrine/annotations 2.0
1 parent d904488 commit 69e7c46

File tree

6 files changed

+71
-34
lines changed

6 files changed

+71
-34
lines changed

.github/workflows/test-application.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
include:
19-
- php-version: '7.2'
20-
elasticsearch-version: '5.6.14'
21-
lint: false
22-
symfony-version: '^2.8'
23-
elasticsearch-package-constraint: '^5.0'
24-
env:
25-
SYMFONY_PHPUNIT_VERSION: '7.5'
26-
2719
- php-version: '7.2'
2820
elasticsearch-version: '5.6.14'
2921
lint: false

DependencyInjection/Compiler/RepositoryPass.php

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

32+
$hasContainerBuildId = $container->hasParameter('container.build_id');
33+
if (!$hasContainerBuildId) {
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+
$hasContainerBuildId = true;
37+
$container->setParameter('container.build_id', hash('crc32', 'Abc123423456789'));
38+
}
39+
3240
$collector = $container->get('es.metadata_collector');
41+
if (!$hasContainerBuildId) {
42+
$container->getParameterBag()->remove('container.build_id');
43+
}
3344

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

DependencyInjection/ONGRElasticsearchExtension.php

Lines changed: 43 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,28 @@
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+
&& \class_exists(\Doctrine\Common\Annotations\PsrCachedReader::class)
34+
) {
35+
$container->prependExtensionConfig(
36+
'framework',
37+
[
38+
'cache' => [
39+
'pools' => [
40+
'es.cache_engine' => [
41+
'adapter' => 'cache.system',
42+
],
43+
],
44+
],
45+
]
46+
);
47+
}
48+
}
49+
2950
/**
3051
* {@inheritdoc}
3152
*/
@@ -68,5 +89,26 @@ public function load(array $configs, ContainerBuilder $container)
6889
);
6990
$definition->setPublic(true);
7091
$container->setDefinition('es.manager_factory', $definition);
92+
93+
if (!\class_exists(\Doctrine\Common\Annotations\PsrCachedReader::class)) {
94+
$container->setDefinition('es.cache_engine', (new Definition(
95+
\Doctrine\Common\Cache\FilesystemCache::class,
96+
[
97+
'%kernel.cache_dir%/ongr/elasticsearch',
98+
'.ongr.data',
99+
]
100+
))->setPublic(true));
101+
}
102+
103+
$container->setDefinition('es.annotations.cached_reader', (new Definition(
104+
\class_exists(\Doctrine\Common\Annotations\PsrCachedReader::class)
105+
? \Doctrine\Common\Annotations\PsrCachedReader::class
106+
: \Doctrine\Common\Annotations\CachedReader::class,
107+
[
108+
new Reference('annotations.reader'),
109+
new Reference('es.cache_engine'),
110+
'%kernel.debug%',
111+
]
112+
))->setPublic(true));
71113
}
72114
}

ONGRElasticsearchBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace ONGR\ElasticsearchBundle;
1313

14+
use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\AnnotationPass;
1415
use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\ManagerPass;
1516
use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\MappingPass;
1617
use ONGR\ElasticsearchBundle\DependencyInjection\Compiler\RepositoryPass;

Resources/config/services.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ 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-
23-
es.annotations.cached_reader:
24-
class: 'Doctrine\Common\Annotations\CachedReader'
25-
public: true
26-
arguments: ["@annotations.reader", "@es.cache_engine", "%kernel.debug%"]
27-
2818
es.document_finder:
2919
class: 'ONGR\ElasticsearchBundle\Mapping\DocumentFinder'
3020
public: true

composer.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,32 @@
1616
],
1717
"require": {
1818
"php": "^7.2|^8.0",
19-
"symfony/framework-bundle": "^2.8|^3.0|^4|^5|^6",
20-
"symfony/console": "^2.8|^3.0|^4|^5|^6",
21-
"symfony/stopwatch": "^2.8|^3.0|^4|^5|^6",
22-
"symfony/templating": "^2.8|^3.0|^4|^5|^6",
23-
"symfony/asset": "^2.8|^3.0|^4|^5|^6",
24-
"doctrine/annotations": "^1.2 || ^2.0",
19+
"symfony/framework-bundle": "^3.0|^4|^5|^6",
20+
"symfony/cache": "^3.4|^4|^5|^6",
21+
"symfony/console": "^3.4|^4|^5|^6",
22+
"symfony/stopwatch": "^3.4|^4|^5|^6",
23+
"symfony/templating": "^3.4|^4|^5|^6",
24+
"symfony/asset": "^3.4|^4|^5|^6",
25+
"doctrine/annotations": "^1.10 || ^2.0",
2526
"doctrine/inflector": "^1.0 || ^2.0",
2627
"doctrine/cache": "~1.4",
2728
"doctrine/collections": "~1.4",
2829
"monolog/monolog": "^1.10 || ^2.0 || ^3.0",
2930
"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"
31+
"symfony/event-dispatcher": "^3.4|^4|^5|^6"
3132
},
3233
"require-dev": {
3334
"mikey179/vfsstream": "~1.4",
3435
"squizlabs/php_codesniffer": "^2.0|^3.0",
35-
"symfony/browser-kit" : "^2.8|^3.4|^4|^5|^6",
36-
"symfony/expression-language" : "^2.8|^3.4|^4|^5|^6",
37-
"symfony/twig-bundle": "^2.8|^3.4|^4|^5|^6",
38-
"symfony/serializer": "^2.8|^3.4|^4|^5|^6",
39-
"symfony/yaml": "^2.8|^3.4|^4|^5|^6",
36+
"symfony/browser-kit" : "^3.4|^4|^5|^6",
37+
"symfony/expression-language" : "^3.4|^4|^5|^6",
38+
"symfony/twig-bundle": "^3.4|^4|^5|^6",
39+
"symfony/serializer": "^3.4|^4|^5|^6",
40+
"symfony/yaml": "^3.4|^4|^5|^6",
4041
"symfony/phpunit-bridge": "^5.1|^6",
41-
"symfony/dependency-injection": "^2.8|^3.4|^4|^5|^6",
42-
"symfony/validator": "^2.8|^3.4|^4|^5|^6",
43-
"symfony/options-resolver": "^2.8|^3.4|^4|^5|^6"
42+
"symfony/dependency-injection": "^3.4|^4|^5|^6",
43+
"symfony/validator": "^3.4|^4|^5|^6",
44+
"symfony/options-resolver": "^3.4|^4|^5|^6"
4445
},
4546
"autoload": {
4647
"psr-4": { "ONGR\\ElasticsearchBundle\\": "" },

0 commit comments

Comments
 (0)