Skip to content

Commit 0dacc4b

Browse files
kuraobiXWB
andcommitted
added support for Symfony 5 (#1592)
Co-authored-by: Karel <[email protected]>
1 parent 724a3c4 commit 0dacc4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+998
-426
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ matrix:
2929
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^3.4"
3030
- php: 7.4
3131
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4.4"
32+
- php: 7.4
33+
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^5.0"
3234

3335
before_install:
3436
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@
1313
],
1414
"require": {
1515
"php": "^7.1",
16-
"symfony/framework-bundle": "^3.4|^4.3",
17-
"symfony/console": "^3.4|^4.3",
18-
"symfony/dependency-injection": "^3.4|^4.3",
19-
"symfony/property-access": "^3.4|^4.3",
16+
"symfony/framework-bundle": "^3.4|^4.3|^5",
17+
"symfony/console": "^3.4|^4.3|^5",
18+
"symfony/dependency-injection": "^3.4|^4.3|^5",
19+
"symfony/property-access": "^3.4|^4.3|^5",
2020
"pagerfanta/pagerfanta": "^1.0.5|^2.0",
2121
"psr/log": "^1.0",
2222
"ruflin/elastica": "^5.3.5|^6.1.1"
2323
},
2424
"require-dev": {
2525
"doctrine/orm": "^2.5",
26-
"doctrine/doctrine-bundle": "^1.6",
26+
"doctrine/doctrine-bundle": "^1.6|^2",
2727
"doctrine/persistence": "^1.3.4",
2828
"doctrine/phpcr-bundle": "^1.3|^2.0",
2929
"doctrine/phpcr-odm": "^1.4",
3030
"jackalope/jackalope-doctrine-dbal": "^1.2",
31-
"jms/serializer-bundle": "^2.2",
32-
"phpunit/phpunit": "^5.7.11|^6.5",
33-
"knplabs/knp-components": "^1.2",
34-
"symfony/expression-language" : "^3.4|^4.3",
35-
"symfony/twig-bundle": "^3.4|^4.3",
36-
"symfony/serializer": "^3.4|^4.3",
37-
"symfony/yaml": "^3.4|^4.3",
31+
"jms/serializer-bundle": "^2.4|^3.5",
32+
"phpunit/phpunit": "^6.5.14",
33+
"knplabs/knp-components": "^1.2|^2.3",
34+
"symfony/expression-language" : "^3.4|^4.3|^5",
35+
"symfony/twig-bundle": "^3.4|^4.3|^5",
36+
"symfony/serializer": "^3.4|^4.3|^5",
37+
"symfony/yaml": "^3.4|^4.3|^5",
3838
"friendsofphp/php-cs-fixer": "^2.2",
39-
"symfony/web-profiler-bundle": "^3.4|^4.3"
39+
"symfony/web-profiler-bundle": "^3.4|^4.3|^5"
4040
},
4141
"suggest": {
4242
"enqueue/elastica-bundle": "The bundle adds extra features to FOSElasticaBundle bundle. Aimed to improve performance."

src/Command/CreateCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function configure()
5555
;
5656
}
5757

58-
protected function execute(InputInterface $input, OutputInterface $output)
58+
protected function execute(InputInterface $input, OutputInterface $output): int
5959
{
6060
$indexName = $input->getOption('index');
6161
$indexes = null === $indexName ? array_keys($this->indexManager->getAllIndexes()) : [$indexName];
@@ -71,5 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
$mapping = $this->mappingBuilder->buildIndexMapping($indexConfig);
7272
$index->create($mapping, false);
7373
}
74+
75+
return 0;
7476
}
7577
}

src/Command/PopulateCommand.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
use Symfony\Component\Console\Input\InputOption;
3232
use Symfony\Component\Console\Output\OutputInterface;
3333
use Symfony\Component\Console\Question\Question;
34-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
34+
use Symfony\Component\EventDispatcher\EventDispatcherInterface as LegacyEventDispatcherInterface;
3535
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
36+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
3637

3738
/**
3839
* Populate the search index.
@@ -42,12 +43,12 @@ class PopulateCommand extends Command
4243
protected static $defaultName = 'fos:elastica:populate';
4344

4445
/**
45-
* @var EventDispatcherInterface
46+
* @var EventDispatcherInterface|LegacyEventDispatcherInterface
4647
*/
4748
private $dispatcher;
4849

4950
/**
50-
* @var IndexManager
51+
* @var IndexManager
5152
*/
5253
private $indexManager;
5354

@@ -72,7 +73,7 @@ class PopulateCommand extends Command
7273
private $resetter;
7374

7475
public function __construct(
75-
EventDispatcherInterface $dispatcher,
76+
$dispatcher,
7677
IndexManager $indexManager,
7778
PagerProviderRegistry $pagerProviderRegistry,
7879
PagerPersisterRegistry $pagerPersisterRegistry,
@@ -125,7 +126,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
125126
}
126127
}
127128

128-
protected function execute(InputInterface $input, OutputInterface $output)
129+
protected function execute(InputInterface $input, OutputInterface $output): int
129130
{
130131
$index = $input->getOption('index');
131132
$type = $input->getOption('type');
@@ -149,7 +150,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
149150
/** @var QuestionHelper $dialog */
150151
$dialog = $this->getHelperSet()->get('question');
151152
if (!$dialog->ask($input, $output, new Question('<question>You chose to reset the index and start indexing with an offset. Do you really want to do that?</question>'))) {
152-
return;
153+
return 0;
153154
}
154155
}
155156

@@ -170,6 +171,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
170171
$this->populateIndex($output, $index, $reset, $options);
171172
}
172173
}
174+
175+
return 0;
173176
}
174177

175178
/**
@@ -183,7 +186,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
183186
private function populateIndex(OutputInterface $output, $index, $reset, $options)
184187
{
185188
$event = new IndexPopulateEvent($index, $reset, $options);
186-
$this->dispatcher->dispatch(IndexPopulateEvent::PRE_INDEX_POPULATE, $event);
189+
$this->dispatch($event, IndexPopulateEvent::PRE_INDEX_POPULATE);
187190

188191
if ($event->isReset()) {
189192
$output->writeln(sprintf('<info>Resetting</info> <comment>%s</comment>', $index));
@@ -195,7 +198,7 @@ private function populateIndex(OutputInterface $output, $index, $reset, $options
195198
$this->populateIndexType($output, $index, $type, false, $event->getOptions());
196199
}
197200

198-
$this->dispatcher->dispatch(IndexPopulateEvent::POST_INDEX_POPULATE, $event);
201+
$this->dispatch($event, IndexPopulateEvent::POST_INDEX_POPULATE);
199202

200203
$this->refreshIndex($output, $index);
201204
}
@@ -212,7 +215,7 @@ private function populateIndex(OutputInterface $output, $index, $reset, $options
212215
private function populateIndexType(OutputInterface $output, $index, $type, $reset, $options)
213216
{
214217
$event = new TypePopulateEvent($index, $type, $reset, $options);
215-
$this->dispatcher->dispatch(TypePopulateEvent::PRE_TYPE_POPULATE, $event);
218+
$this->dispatch($event, TypePopulateEvent::PRE_TYPE_POPULATE);
216219

217220
if ($event->isReset()) {
218221
$output->writeln(sprintf('<info>Resetting</info> <comment>%s/%s</comment>', $index, $type));
@@ -264,7 +267,7 @@ function(PostAsyncInsertObjectsEvent $event) use ($loggerClosure) {
264267

265268
$this->pagerPersister->insert($pager, $options);
266269

267-
$this->dispatcher->dispatch(TypePopulateEvent::POST_TYPE_POPULATE, $event);
270+
$this->dispatch($event, TypePopulateEvent::POST_TYPE_POPULATE);
268271

269272
$this->refreshIndex($output, $index);
270273
}
@@ -281,4 +284,15 @@ private function refreshIndex(OutputInterface $output, $index)
281284
$this->indexManager->getIndex($index)->refresh();
282285
$output->writeln("");
283286
}
287+
288+
private function dispatch($event, $eventName): void
289+
{
290+
if ($this->dispatcher instanceof EventDispatcherInterface) {
291+
// Symfony >= 4.3
292+
$this->dispatcher->dispatch($event, $eventName);
293+
} else {
294+
// Symfony 3.4
295+
$this->dispatcher->dispatch($eventName, $event);
296+
}
297+
}
284298
}

src/Command/ResetCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function configure()
4949
;
5050
}
5151

52-
protected function execute(InputInterface $input, OutputInterface $output)
52+
protected function execute(InputInterface $input, OutputInterface $output): int
5353
{
5454
$index = $input->getOption('index');
5555
$type = $input->getOption('type');
@@ -73,5 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7373
$this->resetter->resetIndex($index, false, $force);
7474
}
7575
}
76+
77+
return 0;
7678
}
7779
}

src/Command/ResetTemplatesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function configure()
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function execute(InputInterface $input, OutputInterface $output)
66+
protected function execute(InputInterface $input, OutputInterface $output): int
6767
{
6868
$indexTemplate = $input->getOption('index');
6969
$deleteByPattern = $input->getOption('force-delete');

src/Command/SearchCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function configure()
5252
;
5353
}
5454

55-
protected function execute(InputInterface $input, OutputInterface $output)
55+
protected function execute(InputInterface $input, OutputInterface $output): int
5656
{
5757
$indexName = $input->getOption('index');
5858
$index = $this->indexManager->getIndex($indexName ? $indexName : null);
@@ -69,6 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6969
foreach ($resultSet->getResults() as $result) {
7070
$output->writeLn($this->formatResult($result, $input->getOption('show-field'), $input->getOption('show-source'), $input->getOption('show-id'), $input->getOption('explain')));
7171
}
72+
73+
return 0;
7274
}
7375

7476
/**

0 commit comments

Comments
 (0)