Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions Command/AbstractManagerAwareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,54 @@
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;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* AbstractElasticsearchCommand class.
*/
abstract class AbstractManagerAwareCommand extends ContainerAwareCommand
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}
*/
Expand Down
27 changes: 21 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ services:
ONGR\ElasticsearchBundle\Command\:
resource: '../../Command'
public: true
arguments: ["@service_container"]
tags:
- { name: console.command }