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 / ServiceManager / Di / DiServiceFactory.php
blob0139f1cef876e9e46f94f9b49414cfc251146e40
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\ServiceManager\Di;
12 use Zend\Di\Di;
13 use Zend\Di\Exception\ClassNotFoundException as DiClassNotFoundException;
14 use Zend\ServiceManager\Exception;
15 use Zend\ServiceManager\FactoryInterface;
16 use Zend\ServiceManager\ServiceLocatorInterface;
18 class DiServiceFactory extends Di implements FactoryInterface
20 /**@#+
21 * constants
23 const USE_SL_BEFORE_DI = 'before';
24 const USE_SL_AFTER_DI = 'after';
25 const USE_SL_NONE = 'none';
26 /**@#-*/
28 /**
29 * @var \Zend\Di\Di
31 protected $di = null;
33 /**
34 * @var \Zend\Di\InstanceManager
36 protected $name = null;
38 /**
39 * @var array
41 protected $parameters = array();
43 /**
44 * @var string
46 protected $useServiceLocator = self::USE_SL_AFTER_DI;
48 /**
49 * @var ServiceLocatorInterface
51 protected $serviceLocator = null;
53 /**
54 * Constructor
56 * @param \Zend\Di\Di $di
57 * @param null|\Zend\Di\InstanceManager $name
58 * @param array $parameters
59 * @param string $useServiceLocator
61 public function __construct(Di $di, $name, array $parameters = array(), $useServiceLocator = self::USE_SL_NONE)
63 $this->di = $di;
64 $this->name = $name;
65 $this->parameters = $parameters;
66 if (in_array($useServiceLocator, array(self::USE_SL_BEFORE_DI, self::USE_SL_AFTER_DI, self::USE_SL_NONE))) {
67 $this->useServiceLocator = $useServiceLocator;
70 // since we are using this in a proxy-fashion, localize state
71 $this->definitions = $this->di->definitions;
72 $this->instanceManager = $this->di->instanceManager;
75 /**
76 * Create service
78 * @param ServiceLocatorInterface $serviceLocator
79 * @return object
81 public function createService(ServiceLocatorInterface $serviceLocator)
83 $this->serviceLocator = $serviceLocator;
84 return $this->get($this->name, $this->parameters);
87 /**
88 * Override, as we want it to use the functionality defined in the proxy
90 * @param string $name
91 * @param array $params
92 * @return object
93 * @throws Exception\ServiceNotFoundException
95 public function get($name, array $params = array())
97 // allow this di service to get dependencies from the service locator BEFORE trying di
98 if ($this->useServiceLocator == self::USE_SL_BEFORE_DI && $this->serviceLocator->has($name)) {
99 return $this->serviceLocator->get($name);
102 try {
104 $service = parent::get($name, $params);
105 return $service;
107 } catch (DiClassNotFoundException $e) {
109 // allow this di service to get dependencies from the service locator AFTER trying di
110 if ($this->useServiceLocator == self::USE_SL_AFTER_DI && $this->serviceLocator->has($name)) {
111 return $this->serviceLocator->get($name);
112 } else {
113 throw new Exception\ServiceNotFoundException(
114 sprintf('Service %s was not found in this DI instance', $name),
115 null,