Remove ContainerAwareCommand from commands

And use DI to retrieve services in commands (except for `RedisWorkerCommand` where the container is injected, hard to find a better way, at least for now).
This commit is contained in:
Jeremy Benoist
2022-12-15 20:57:02 +01:00
parent 9c16dd7bd1
commit 5832482a10
14 changed files with 290 additions and 169 deletions

View File

@ -3,15 +3,25 @@
namespace Wallabag\ImportBundle\Command;
use Simpleue\Worker\QueueWorker;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RedisWorkerCommand extends ContainerAwareCommand
class RedisWorkerCommand extends Command
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
protected function configure()
{
$this
@ -29,13 +39,13 @@ class RedisWorkerCommand extends ContainerAwareCommand
$serviceName = $input->getArgument('serviceName');
if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
if (!$this->container->has('wallabag_import.queue.redis.' . $serviceName) || !$this->container->has('wallabag_import.consumer.redis.' . $serviceName)) {
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
}
$worker = new QueueWorker(
$this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
$this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
$this->container->get('wallabag_import.queue.redis.' . $serviceName),
$this->container->get('wallabag_import.consumer.redis.' . $serviceName),
(int) $input->getOption('maxIterations')
);