Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Mvc / Service / ServiceManagerConfig.php
blob2514bf2153c45d0ef07db0a9dce63a3cb8318f93
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mvc\Service;
12 use Zend\EventManager\EventManagerAwareInterface;
13 use Zend\EventManager\EventManagerInterface;
14 use Zend\ServiceManager\ConfigInterface;
15 use Zend\ServiceManager\ServiceLocatorAwareInterface;
16 use Zend\ServiceManager\ServiceManager;
17 use Zend\ServiceManager\ServiceManagerAwareInterface;
19 class ServiceManagerConfig implements ConfigInterface
21 /**
22 * Services that can be instantiated without factories
24 * @var array
26 protected $invokables = array(
27 'SharedEventManager' => 'Zend\EventManager\SharedEventManager',
30 /**
31 * Service factories
33 * @var array
35 protected $factories = array(
36 'EventManager' => 'Zend\Mvc\Service\EventManagerFactory',
37 'ModuleManager' => 'Zend\Mvc\Service\ModuleManagerFactory',
40 /**
41 * Abstract factories
43 * @var array
45 protected $abstractFactories = array();
47 /**
48 * Aliases
50 * @var array
52 protected $aliases = array(
53 'Zend\EventManager\EventManagerInterface' => 'EventManager',
56 /**
57 * Shared services
59 * Services are shared by default; this is primarily to indicate services
60 * that should NOT be shared
62 * @var array
64 protected $shared = array(
65 'EventManager' => false,
68 /**
69 * Constructor
71 * Merges internal arrays with those passed via configuration
73 * @param array $configuration
75 public function __construct(array $configuration = array())
77 if (isset($configuration['invokables'])) {
78 $this->invokables = array_merge($this->invokables, $configuration['invokables']);
81 if (isset($configuration['factories'])) {
82 $this->factories = array_merge($this->factories, $configuration['factories']);
85 if (isset($configuration['abstract_factories'])) {
86 $this->abstractFactories = array_merge($this->abstractFactories, $configuration['abstract_factories']);
89 if (isset($configuration['aliases'])) {
90 $this->aliases = array_merge($this->aliases, $configuration['aliases']);
93 if (isset($configuration['shared'])) {
94 $this->shared = array_merge($this->shared, $configuration['shared']);
99 /**
100 * Configure the provided service manager instance with the configuration
101 * in this class.
103 * In addition to using each of the internal properties to configure the
104 * service manager, also adds an initializer to inject ServiceManagerAware
105 * and ServiceLocatorAware classes with the service manager.
107 * @param ServiceManager $serviceManager
108 * @return void
110 public function configureServiceManager(ServiceManager $serviceManager)
112 foreach ($this->invokables as $name => $class) {
113 $serviceManager->setInvokableClass($name, $class);
116 foreach ($this->factories as $name => $factoryClass) {
117 $serviceManager->setFactory($name, $factoryClass);
120 foreach ($this->abstractFactories as $factoryClass) {
121 $serviceManager->addAbstractFactory($factoryClass);
124 foreach ($this->aliases as $name => $service) {
125 $serviceManager->setAlias($name, $service);
128 foreach ($this->shared as $name => $value) {
129 $serviceManager->setShared($name, $value);
132 $serviceManager->addInitializer(function ($instance) use ($serviceManager) {
133 if ($instance instanceof EventManagerAwareInterface) {
134 if ($instance->getEventManager() instanceof EventManagerInterface) {
135 $instance->getEventManager()->setSharedManager(
136 $serviceManager->get('SharedEventManager')
138 } else {
139 $instance->setEventManager($serviceManager->get('EventManager'));
144 $serviceManager->addInitializer(function ($instance) use ($serviceManager) {
145 if ($instance instanceof ServiceManagerAwareInterface) {
146 $instance->setServiceManager($serviceManager);
150 $serviceManager->addInitializer(function ($instance) use ($serviceManager) {
151 if ($instance instanceof ServiceLocatorAwareInterface) {
152 $instance->setServiceLocator($serviceManager);
156 $serviceManager->setService('ServiceManager', $serviceManager);
157 $serviceManager->setAlias('Zend\ServiceManager\ServiceLocatorInterface', 'ServiceManager');
158 $serviceManager->setAlias('Zend\ServiceManager\ServiceManager', 'ServiceManager');