1414use ONGR \ElasticsearchBundle \DependencyInjection \Configuration ;
1515use ONGR \ElasticsearchBundle \Service \IndexService ;
1616use Symfony \Bundle \FrameworkBundle \Command \ContainerAwareCommand ;
17+ use Symfony \Component \Console \Command \Command ;
1718use Symfony \Component \Console \Input \InputOption ;
19+ use Symfony \Component \DependencyInjection \Container ;
1820
19- abstract class AbstractIndexServiceAwareCommand extends ContainerAwareCommand
21+ abstract class AbstractIndexServiceAwareCommand extends Command
2022{
23+ private $ container ;
24+
2125 const INDEX_OPTION = 'index ' ;
2226
27+ public function __construct (Container $ container )
28+ {
29+ $ this ->container = $ container ;
30+ parent ::__construct ();
31+ }
32+
2333 protected function configure ()
2434 {
2535 $ this ->addOption (
@@ -32,19 +42,24 @@ protected function configure()
3242
3343 protected function getIndex ($ name ): IndexService
3444 {
35- $ name = $ name ?? $ this ->getContainer () ->getParameter (Configuration::ONGR_DEFAULT_INDEX );
36- $ indexes = $ this ->getContainer () ->getParameter (Configuration::ONGR_INDEXES );
45+ $ name = $ name ?? $ this ->container ->getParameter (Configuration::ONGR_DEFAULT_INDEX );
46+ $ indexes = $ this ->container ->getParameter (Configuration::ONGR_INDEXES );
3747
38- if (isset ($ indexes [$ name ]) && $ this ->getContainer () ->has ($ indexes [$ name ])) {
39- return $ this ->getContainer () ->get ($ indexes [$ name ]);
48+ if (isset ($ indexes [$ name ]) && $ this ->container ->has ($ indexes [$ name ])) {
49+ return $ this ->container ->get ($ indexes [$ name ]);
4050 }
4151
4252 throw new \RuntimeException (
4353 sprintf (
4454 'There is no index under `%s` name found. Available options: `%s`. ' ,
4555 $ name ,
46- implode ('`, ` ' , array_keys ($ this ->getContainer () ->getParameter (Configuration::ONGR_INDEXES )))
56+ implode ('`, ` ' , array_keys ($ this ->container ->getParameter (Configuration::ONGR_INDEXES )))
4757 )
4858 );
4959 }
60+
61+ public function getContainer (): Container
62+ {
63+ return $ this ->container ;
64+ }
5065}
0 commit comments