Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (40 sloc) 1.75 KB
<?php
namespace Ctrl\Service;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config;
use Zend\EventManager\EventManagerAwareInterface;
use Ctrl\ServiceManager\EntityManagerAwareInterface;
class DomainServiceLoaderFactory implements FactoryInterface
{
/**
* @param ServiceLocatorInterface|ServiceManager $serviceLocator
* @return mixed
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('Configuration');
$serviceConfig = new Config(
isset($config['domain_services']) ? $config['domain_services'] : array()
);
$domainServiceFactory = new ServiceManager($serviceConfig);
$serviceLocator->addPeeringServiceManager($domainServiceFactory);
$domainServiceFactory->addInitializer(function ($instance) use ($serviceLocator) {
if ($instance instanceof ServiceLocatorAwareInterface)
$instance->setServiceLocator($serviceLocator->get('Zend\ServiceManager\ServiceLocatorInterface'));
if ($instance instanceof EventManagerAwareInterface)
$instance->setEventManager($serviceLocator->get('EventManager'));
if ($instance instanceof EntityManagerAwareInterface) {
try {
$instance->setEntityManager($serviceLocator->get('EntityManager'));
} catch (\Zend\ServiceManager\Exception\ServiceNotFoundException $e) {
// no entitymanager set
// TODO: log
}
}
});
return $domainServiceFactory;
}
}