Source of file ServiceManagerConfig.php
Size: 5,131 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Mvc/Service/ServiceManagerConfig.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Mvc\Service; use Zend\EventManager\EventManagerAwareInterface; use Zend\EventManager\EventManagerInterface; use Zend\ServiceManager\ConfigInterface; use Zend\ServiceManager\ServiceLocatorAwareInterface; use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManagerAwareInterface; class ServiceManagerConfig implements ConfigInterface { /** * Services that can be instantiated without factories * * @var array */ protected $invokables = array( 'SharedEventManager' => 'Zend\EventManager\SharedEventManager', ); /** * Service factories * * @var array */ protected $factories = array( 'EventManager' => 'Zend\Mvc\Service\EventManagerFactory', 'ModuleManager' => 'Zend\Mvc\Service\ModuleManagerFactory', ); /** * Abstract factories * * @var array */ protected $abstractFactories = array(); /** * Aliases * * @var array */ protected $aliases = array( 'Zend\EventManager\EventManagerInterface' => 'EventManager', ); /** * Shared services * * Services are shared by default; this is primarily to indicate services * that should NOT be shared * * @var array */ protected $shared = array( 'EventManager' => false, ); /** * Constructor * * Merges internal arrays with those passed via configuration * * @param array $configuration */ public function __construct(array $configuration = array()) { if (isset($configuration['invokables'])) { $this->invokables = array_merge($this->invokables, $configuration['invokables']); } if (isset($configuration['factories'])) { $this->factories = array_merge($this->factories, $configuration['factories']); } if (isset($configuration['abstract_factories'])) { $this->abstractFactories = array_merge($this->abstractFactories, $configuration['abstract_factories']); } if (isset($configuration['aliases'])) { $this->aliases = array_merge($this->aliases, $configuration['aliases']); } if (isset($configuration['shared'])) { $this->shared = array_merge($this->shared, $configuration['shared']); } } /** * Configure the provided service manager instance with the configuration * in this class. * * In addition to using each of the internal properties to configure the * service manager, also adds an initializer to inject ServiceManagerAware * and ServiceLocatorAware classes with the service manager. * * @param ServiceManager $serviceManager * @return void */ public function configureServiceManager(ServiceManager $serviceManager) { foreach ($this->invokables as $name => $class) { $serviceManager->setInvokableClass($name, $class); } foreach ($this->factories as $name => $factoryClass) { $serviceManager->setFactory($name, $factoryClass); } foreach ($this->abstractFactories as $factoryClass) { $serviceManager->addAbstractFactory($factoryClass); } foreach ($this->aliases as $name => $service) { $serviceManager->setAlias($name, $service); } foreach ($this->shared as $name => $value) { $serviceManager->setShared($name, $value); } $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof EventManagerAwareInterface) { if ($instance->getEventManager() instanceof EventManagerInterface) { $instance->getEventManager()->setSharedManager( $serviceManager->get('SharedEventManager') ); } else { $instance->setEventManager($serviceManager->get('EventManager')); } } }); $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof ServiceManagerAwareInterface) { $instance->setServiceManager($serviceManager); } }); $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof ServiceLocatorAwareInterface) { $instance->setServiceLocator($serviceManager); } }); $serviceManager->setService('ServiceManager', $serviceManager); $serviceManager->setAlias('Zend\ServiceManager\ServiceLocatorInterface', 'ServiceManager'); $serviceManager->setAlias('Zend\ServiceManager\ServiceManager', 'ServiceManager'); } } |