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

Corrections pour passer à ZF3.

parent a5a9a840
Loading
Loading
Loading
Loading
+19 −17
Original line number Diff line number Diff line
@@ -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');

@@ -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