Loading src/UnicaenFaq/Service/FaqServiceFactory.php +19 −17 Original line number Diff line number Diff line Loading @@ -3,32 +3,19 @@ namespace UnicaenFaq\Service; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Exception\InvalidArgumentException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; final class FaqServiceFactory implements FactoryInterface { /** * @param ServiceLocatorInterface $serviceLocator * @return FaqService */ public function createService(ServiceLocatorInterface $serviceLocator) { $faqEntityClass = $this->getFaqEntityClass($serviceLocator); if (!class_exists($faqEntityClass)) { throw new InvalidArgumentException("La classe spécifiée dans l'option de 'unicaen-faq.faq_entity_class' n'existe pas"); return $this->__invoke($serviceLocator, '?'); } $em = $this->getEntityManager($serviceLocator); $service = new FaqService($em, $faqEntityClass); return $service; } private function getEntityManager(ServiceLocatorInterface $serviceLocator) private function getEntityManager(ContainerInterface $serviceLocator) { $config = $serviceLocator->get('config'); Loading @@ -44,7 +31,7 @@ final class FaqServiceFactory implements FactoryInterface return $em; } private function getFaqEntityClass(ServiceLocatorInterface $serviceLocator) private function getFaqEntityClass(ContainerInterface $serviceLocator) { $config = $serviceLocator->get('config'); Loading @@ -54,4 +41,19 @@ final class FaqServiceFactory implements FactoryInterface return $config['unicaen-faq']['faq_entity_class']; } public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $faqEntityClass = $this->getFaqEntityClass($container); if (!class_exists($faqEntityClass)) { throw new InvalidArgumentException("La classe spécifiée dans l'option de 'unicaen-faq.faq_entity_class' n'existe pas"); } $em = $this->getEntityManager($container); $service = new FaqService($em, $faqEntityClass); return $service; } } No newline at end of file Loading
src/UnicaenFaq/Service/FaqServiceFactory.php +19 −17 Original line number Diff line number Diff line Loading @@ -3,32 +3,19 @@ namespace UnicaenFaq\Service; use Doctrine\ORM\EntityManager; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Exception\InvalidArgumentException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; final class FaqServiceFactory implements FactoryInterface { /** * @param ServiceLocatorInterface $serviceLocator * @return FaqService */ public function createService(ServiceLocatorInterface $serviceLocator) { $faqEntityClass = $this->getFaqEntityClass($serviceLocator); if (!class_exists($faqEntityClass)) { throw new InvalidArgumentException("La classe spécifiée dans l'option de 'unicaen-faq.faq_entity_class' n'existe pas"); return $this->__invoke($serviceLocator, '?'); } $em = $this->getEntityManager($serviceLocator); $service = new FaqService($em, $faqEntityClass); return $service; } private function getEntityManager(ServiceLocatorInterface $serviceLocator) private function getEntityManager(ContainerInterface $serviceLocator) { $config = $serviceLocator->get('config'); Loading @@ -44,7 +31,7 @@ final class FaqServiceFactory implements FactoryInterface return $em; } private function getFaqEntityClass(ServiceLocatorInterface $serviceLocator) private function getFaqEntityClass(ContainerInterface $serviceLocator) { $config = $serviceLocator->get('config'); Loading @@ -54,4 +41,19 @@ final class FaqServiceFactory implements FactoryInterface return $config['unicaen-faq']['faq_entity_class']; } public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $faqEntityClass = $this->getFaqEntityClass($container); if (!class_exists($faqEntityClass)) { throw new InvalidArgumentException("La classe spécifiée dans l'option de 'unicaen-faq.faq_entity_class' n'existe pas"); } $em = $this->getEntityManager($container); $service = new FaqService($em, $faqEntityClass); return $service; } } No newline at end of file