mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-03 21:34:59 +00:00
resolving deprecated private service injection on commands classes
This commit is contained in:
@@ -19,21 +19,48 @@
|
||||
|
||||
namespace Chill\MainBundle\Command;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LoadPostalCodesCommand
|
||||
*
|
||||
* @package Chill\MainBundle\Command
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadPostalCodesCommand extends ContainerAwareCommand
|
||||
class LoadPostalCodesCommand extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* @var EntityManager
|
||||
*/
|
||||
private $entityManager;
|
||||
|
||||
/**
|
||||
* @var ValidatorInterface
|
||||
*/
|
||||
private $validator;
|
||||
|
||||
/**
|
||||
* LoadPostalCodesCommand constructor.
|
||||
*
|
||||
* @param EntityManager $entityManager
|
||||
* @param ValidatorInterface $validator
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager, ValidatorInterface $validator)
|
||||
{
|
||||
$this->entityManager = $entityManager;
|
||||
$this->validator = $validator;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('chill:main:postal-code:populate')
|
||||
@@ -105,7 +132,7 @@ class LoadPostalCodesCommand extends ContainerAwareCommand
|
||||
$line ++;
|
||||
}
|
||||
|
||||
$this->getContainer()->get('doctrine.orm.entity_manager')->flush();
|
||||
$this->entityManager->flush();
|
||||
|
||||
$output->writeln('<info>'.$num.' were added !</info>');
|
||||
}
|
||||
@@ -134,7 +161,7 @@ class LoadPostalCodesCommand extends ContainerAwareCommand
|
||||
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
||||
$output->writeln('handling row: '. $row[0].' | '. $row[1].' | '. $row[2]);
|
||||
}
|
||||
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
|
||||
$em = $this->entityManager;
|
||||
$country = $em
|
||||
->getRepository('ChillMainBundle:Country')
|
||||
->findOneBy(array('countryCode' => $row[2]));
|
||||
@@ -160,7 +187,7 @@ class LoadPostalCodesCommand extends ContainerAwareCommand
|
||||
->setCountry($country)
|
||||
;
|
||||
|
||||
$errors = $this->getContainer()->get('validator')->validate($postalCode);
|
||||
$errors = $this->validator->validate($postalCode);
|
||||
|
||||
if ($errors->count() == 0) {
|
||||
$em->persist($postalCode);
|
||||
|
Reference in New Issue
Block a user