From 100d9fe7d0764e52ffd9f583a6a58ebf4ce8ab4b Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Fri, 22 Jul 2016 15:15:21 +0200 Subject: [PATCH] ServiceLocator deprecated --- .../Application/Controller/FileController.php | 20 ++++++++++++++----- .../Controller/FileControllerFactory.php | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/module/Application/src/Application/Controller/FileController.php b/module/Application/src/Application/Controller/FileController.php index 4f74170..e375373 100644 --- a/module/Application/src/Application/Controller/FileController.php +++ b/module/Application/src/Application/Controller/FileController.php @@ -6,6 +6,7 @@ use Zend\Console\Request as ConsoleRequest; use Zend\Mvc\Controller\AbstractActionController; use Zend\Stdlib\RequestInterface; use Zend\Stdlib\ResponseInterface; +use Doctrine\ORM\EntityManager; class FileController extends AbstractActionController { @@ -19,14 +20,20 @@ class FileController extends AbstractActionController */ protected $appConfig; + /** + * @var \Doctrine\ORM\EntityManager object + */ + protected $entityManager; + /** * @param Console $console * @param array $appConfig */ - public function __construct(Console $console, array $appConfig) + public function __construct(Console $console, EntityManager $em, array $appConfig) { - $this->console = $console; - $this->appConfig = $appConfig; + $this->console = $console; + $this->entityManager = $em; + $this->appConfig = $appConfig; } /** @@ -53,10 +60,11 @@ class FileController extends AbstractActionController { $request = $this->getRequest(); $verbose = $request->getParam('verbose', false) || $request->getParam('v', false); + $dryrun = $request->getParam('dry-run', false) || $request->getParam('n', false); + // Get file not sent - $em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager'); - $results = $em->getRepository('Application\Entity\FluxFileout')->getNotSent(); + $results = $this->entityManager->getRepository('Application\Entity\FluxFileout')->getNotSent(); if (count($results) == 0) { $this->output("Rien à traiter.", $verbose); } else { @@ -69,6 +77,8 @@ class FileController extends AbstractActionController $this->output("", $verbose); } } + + // Last line blank to always add a carrier return in console $this->output("", $verbose); } diff --git a/module/Application/src/Application/Controller/FileControllerFactory.php b/module/Application/src/Application/Controller/FileControllerFactory.php index 6f35103..bfbcfcd 100644 --- a/module/Application/src/Application/Controller/FileControllerFactory.php +++ b/module/Application/src/Application/Controller/FileControllerFactory.php @@ -11,8 +11,9 @@ class FileControllerFactory implements FactoryInterface { $serviceLocator = $serviceLocator->getServiceLocator(); $console = $serviceLocator->get('Console'); - $appConfig = $serviceLocator->get('config'); + $config = $serviceLocator->get('config'); + $em = $serviceLocator->get('Doctrine\ORM\EntityManager'); - return new FileController($console, $appConfig); + return new FileController($console, $em, $config); } }