Commit 81666568 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Corrections pour passer à ZF3.

parent a5a9a840
......@@ -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");
}
$em = $this->getEntityManager($serviceLocator);
$service = new FaqService($em, $faqEntityClass);
return $service;
return $this->__invoke($serviceLocator, '?');
}
private function getEntityManager(ServiceLocatorInterface $serviceLocator)
private function getEntityManager(ContainerInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
......@@ -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');
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment