From ee0b5a52646191670a5bbbe11c7e4f7eb4f6e2e4 Mon Sep 17 00:00:00 2001 From: Peter Svistunov Date: Fri, 13 Sep 2019 11:02:34 +0800 Subject: [PATCH 1/3] Fix deprecation for symfony/config 4.2+ --- DependencyInjection/Configuration.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0883bcad..b6f41acc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,8 +25,13 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('ongr_elasticsearch'); + $treeBuilder = new TreeBuilder('ongr_elasticsearch'); + if (\method_exists($treeBuilder, 'getRootNode')) { + $rootNode = $treeBuilder->getRootNode(); + } else { + // backward compatibility for symfony/config <= 4.1 + $rootNode = $treeBuilder->root('ongr_elasticsearch'); + } $rootNode ->children() @@ -56,8 +61,13 @@ public function getConfigTreeBuilder() */ private function getAnalysisNode() { - $builder = new TreeBuilder(); - $node = $builder->root('analysis'); + $builder = new TreeBuilder('analysis'); + if (\method_exists($builder, 'getRootNode')) { + $node = $builder->getRootNode(); + } else { + // backward compatibility for symfony/config <= 4.1 + $node = $builder->root('analysis'); + } $node ->info('Defines analyzers, normalizers, tokenizers and filters') @@ -95,8 +105,13 @@ private function getAnalysisNode() */ private function getManagersNode() { - $builder = new TreeBuilder(); - $node = $builder->root('managers'); + $builder = new TreeBuilder('managers'); + if (\method_exists($builder, 'getRootNode')) { + $node = $builder->getRootNode(); + } else { + // backward compatibility for symfony/config <= 4.1 + $node = $builder->root('managers'); + } $node ->isRequired() From 8dc70416e6e967104e107e1d86c1d2f02ec41f5e Mon Sep 17 00:00:00 2001 From: Peter Svistunov Date: Fri, 13 Sep 2019 12:56:51 +0800 Subject: [PATCH 2/3] Fix deprecation for symfony/config 4.2+ --- Command/AbstractManagerAwareCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Command/AbstractManagerAwareCommand.php b/Command/AbstractManagerAwareCommand.php index 8a8905e8..5da9e4bd 100644 --- a/Command/AbstractManagerAwareCommand.php +++ b/Command/AbstractManagerAwareCommand.php @@ -12,13 +12,13 @@ namespace ONGR\ElasticsearchBundle\Command; use ONGR\ElasticsearchBundle\Service\Manager; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; /** * AbstractElasticsearchCommand class. */ -abstract class AbstractManagerAwareCommand extends ContainerAwareCommand +abstract class AbstractManagerAwareCommand extends Command { /** * {@inheritdoc} From df8fccb7987b217141ec08cab11f2c50f36763d9 Mon Sep 17 00:00:00 2001 From: Peter Svistunov Date: Thu, 19 Sep 2019 12:54:19 +0800 Subject: [PATCH 3/3] Fix symfony 4.2 command related deprecations --- Command/AbstractManagerAwareCommand.php | 40 +++++++++++++++++++++++++ Resources/config/services4.yaml | 1 + 2 files changed, 41 insertions(+) diff --git a/Command/AbstractManagerAwareCommand.php b/Command/AbstractManagerAwareCommand.php index 5da9e4bd..3633f459 100644 --- a/Command/AbstractManagerAwareCommand.php +++ b/Command/AbstractManagerAwareCommand.php @@ -14,12 +14,52 @@ use ONGR\ElasticsearchBundle\Service\Manager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * AbstractElasticsearchCommand class. */ abstract class AbstractManagerAwareCommand extends Command { + + /** + * @var ContainerInterface|null + */ + private $container; + + public function __construct(ContainerInterface $container) + { + $this->container = $container; + parent::__construct(); + } + + /** + * @return ContainerInterface + * + * @throws \LogicException + */ + protected function getContainer() + { + if (null === $this->container) { + $application = $this->getApplication(); + if (null === $application) { + throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.'); + } + + $this->container = $application->getKernel()->getContainer(); + } + + return $this->container; + } + + /** + * {@inheritdoc} + */ + public function setContainer(ContainerInterface $container = null) + { + $this->container = $container; + } + /** * {@inheritdoc} */ diff --git a/Resources/config/services4.yaml b/Resources/config/services4.yaml index 5b480602..cb3fe995 100644 --- a/Resources/config/services4.yaml +++ b/Resources/config/services4.yaml @@ -2,5 +2,6 @@ services: ONGR\ElasticsearchBundle\Command\: resource: '../../Command' public: true + arguments: ["@service_container"] tags: - { name: console.command } \ No newline at end of file