From f63c4b42e0167cc639ac87a6bda30fe4aac797ac Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 26 Jan 2021 13:47:35 +0100 Subject: [PATCH] resolving deprecated private service injection on commands classes --- Command/ImportPeopleFromCSVCommand.php | 43 ++++++++++++++++++-------- config/services/command.yaml | 21 +++++++------ 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Command/ImportPeopleFromCSVCommand.php b/Command/ImportPeopleFromCSVCommand.php index d8055d9da..d5e4c597c 100644 --- a/Command/ImportPeopleFromCSVCommand.php +++ b/Command/ImportPeopleFromCSVCommand.php @@ -19,7 +19,10 @@ namespace Chill\PersonBundle\Command; -use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Chill\MainBundle\Templating\TranslatableStringHelper; +use Doctrine\ORM\EntityManagerInterface; +use Psr\Log\LoggerInterface; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -36,6 +39,7 @@ use Chill\CustomFieldsBundle\Service\CustomFieldProvider; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\Event; +use Symfony\Component\Form\FormFactory; /** * Class ImportPeopleFromCSVCommand @@ -43,7 +47,7 @@ use Symfony\Component\EventDispatcher\Event; * @package Chill\PersonBundle\Command * @author Julien Fastré */ -class ImportPeopleFromCSVCommand extends ContainerAwareCommand +class ImportPeopleFromCSVCommand extends Command { /** * @var InputInterface @@ -124,19 +128,36 @@ class ImportPeopleFromCSVCommand extends ContainerAwareCommand * @var string */ protected static $defaultDateInterpreter = "%d/%m/%Y|%e/%m/%y|%d/%m/%Y|%e/%m/%Y"; - + + /** + * @var FormFactory + */ + protected $formFactory; + + /** + * ImportPeopleFromCSVCommand constructor. + * + * @param LoggerInterface $logger + * @param TranslatableStringHelper $helper + * @param EntityManagerInterface $em + * @param CustomFieldProvider $customFieldProvider + * @param EventDispatcherInterface $eventDispatcher + * @param FormFactory $formFactory + */ public function __construct( - \Psr\Log\LoggerInterface $logger, - \Chill\MainBundle\Templating\TranslatableStringHelper $helper, - \Doctrine\ORM\EntityManagerInterface $em, + LoggerInterface $logger, + TranslatableStringHelper $helper, + EntityManagerInterface $em, CustomFieldProvider $customFieldProvider, - EventDispatcherInterface $eventDispatcher + EventDispatcherInterface $eventDispatcher, + FormFactory $formFactory ) { $this->logger = $logger; $this->helper = $helper; $this->em = $em; $this->customFieldProvider = $customFieldProvider; $this->eventDispatcher = $eventDispatcher; + $this->formFactory = $formFactory; parent::__construct('chill:person:import'); } @@ -393,9 +414,6 @@ EOF $this->logger->debug("Setting locale to ".$input->getArgument('locale')); setlocale(LC_TIME, $input->getArgument('locale')); - /* @var $em \Doctrine\Persistence\ObjectManager */ - $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); - // opening csv as resource $csv = $this->openCSV(); @@ -857,15 +875,14 @@ EOF */ protected function processingCustomFields(Person $person, $row) { - /* @var $factory \Symfony\Component\Form\FormFactory */ - $factory = $this->getContainer()->get('form.factory'); + /* @var $cfProvider \Chill\CustomFieldsBundle\Service\CustomFieldProvider */ $cfProvider = $this->customFieldProvider; $cfData = array(); /* @var $$customField \Chill\CustomFieldsBundle\Entity\CustomField */ foreach($this->customFieldMapping as $rowNumber => $customField) { - $builder = $factory->createBuilder(); + $builder = $this->formFactory->createBuilder(); $cfProvider->getCustomFieldByType($customField->getType()) ->buildForm($builder, $customField); $form = $builder->getForm(); diff --git a/config/services/command.yaml b/config/services/command.yaml index 59a2f984a..685a348dd 100644 --- a/config/services/command.yaml +++ b/config/services/command.yaml @@ -1,14 +1,4 @@ services: - Chill\PersonBundle\Command\ImportPeopleFromCSVCommand: - arguments: - $logger: '@logger' - $helper: '@Chill\MainBundle\Templating\TranslatableStringHelper' - $em: '@Doctrine\ORM\EntityManagerInterface' - $customFieldProvider: '@Chill\CustomFieldsBundle\Service\CustomFieldProvider' - $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' - tags: - - { name: console.command } - Chill\PersonBundle\Command\ChillPersonMoveCommand: arguments: $em: '@Doctrine\ORM\EntityManagerInterface' @@ -16,3 +6,14 @@ services: $chillLogger: '@chill.main.logger' tags: - { name: console.command } + + Chill\PersonBundle\Command\ImportPeopleFromCSVCommand: + arguments: + $logger: '@logger' + $helper: '@Chill\MainBundle\Templating\TranslatableStringHelper' + $em: '@Doctrine\ORM\EntityManagerInterface' + $customFieldProvider: '@Chill\CustomFieldsBundle\Service\CustomFieldProvider' + $eventDispatcher: '@Symfony\Component\EventDispatcher\EventDispatcherInterface' + $formFactory: '@form.factory' + tags: + - { name: console.command }