ServiceLocator deprecated

This commit is contained in:
Michael RICOIS 2016-07-22 15:15:21 +02:00
parent 1f87bac0f4
commit 100d9fe7d0
2 changed files with 18 additions and 7 deletions

View File

@ -6,6 +6,7 @@ use Zend\Console\Request as ConsoleRequest;
use Zend\Mvc\Controller\AbstractActionController; use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\RequestInterface; use Zend\Stdlib\RequestInterface;
use Zend\Stdlib\ResponseInterface; use Zend\Stdlib\ResponseInterface;
use Doctrine\ORM\EntityManager;
class FileController extends AbstractActionController class FileController extends AbstractActionController
{ {
@ -19,14 +20,20 @@ class FileController extends AbstractActionController
*/ */
protected $appConfig; protected $appConfig;
/**
* @var \Doctrine\ORM\EntityManager object
*/
protected $entityManager;
/** /**
* @param Console $console * @param Console $console
* @param array $appConfig * @param array $appConfig
*/ */
public function __construct(Console $console, array $appConfig) public function __construct(Console $console, EntityManager $em, array $appConfig)
{ {
$this->console = $console; $this->console = $console;
$this->appConfig = $appConfig; $this->entityManager = $em;
$this->appConfig = $appConfig;
} }
/** /**
@ -53,10 +60,11 @@ class FileController extends AbstractActionController
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$verbose = $request->getParam('verbose', false) || $request->getParam('v', false); $verbose = $request->getParam('verbose', false) || $request->getParam('v', false);
$dryrun = $request->getParam('dry-run', false) || $request->getParam('n', false);
// Get file not sent // Get file not sent
$em = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager'); $results = $this->entityManager->getRepository('Application\Entity\FluxFileout')->getNotSent();
$results = $em->getRepository('Application\Entity\FluxFileout')->getNotSent();
if (count($results) == 0) { if (count($results) == 0) {
$this->output("Rien à traiter.", $verbose); $this->output("Rien à traiter.", $verbose);
} else { } else {
@ -69,6 +77,8 @@ class FileController extends AbstractActionController
$this->output("", $verbose); $this->output("", $verbose);
} }
} }
// Last line blank to always add a carrier return in console
$this->output("", $verbose); $this->output("", $verbose);
} }

View File

@ -11,8 +11,9 @@ class FileControllerFactory implements FactoryInterface
{ {
$serviceLocator = $serviceLocator->getServiceLocator(); $serviceLocator = $serviceLocator->getServiceLocator();
$console = $serviceLocator->get('Console'); $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);
} }
} }