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 / Proxy / LazyServiceFactory.php
blobeb033680b911c3d60dacbdc766c4322f8dc6f234
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\Proxy;
12 use ProxyManager\Factory\LazyLoadingValueHolderFactory;
14 use ProxyManager\Proxy\LazyLoadingInterface;
15 use Zend\ServiceManager\DelegatorFactoryInterface;
16 use Zend\ServiceManager\Exception;
17 use Zend\ServiceManager\ServiceLocatorInterface;
19 /**
20 * Delegator factory responsible of instantiating lazy loading value holder proxies of
21 * given services at runtime
23 * @link https://github.com/Ocramius/ProxyManager/blob/master/docs/lazy-loading-value-holder.md
25 class LazyServiceFactory implements DelegatorFactoryInterface
27 /**
28 * @var \ProxyManager\Factory\LazyLoadingValueHolderFactory
30 protected $proxyFactory;
32 /**
33 * @var string[] map of service names to class names
35 protected $servicesMap;
37 /**
38 * @param LazyLoadingValueHolderFactory $proxyFactory
39 * @param string[] $servicesMap a map of service names to class names of their
40 * respective classes
42 public function __construct(LazyLoadingValueHolderFactory $proxyFactory, array $servicesMap)
44 $this->proxyFactory = $proxyFactory;
45 $this->servicesMap = $servicesMap;
48 /**
49 * {@inheritDoc}
51 * @return object|\ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface
53 public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
55 $initializer = function (& $wrappedInstance, LazyLoadingInterface $proxy) use ($callback) {
56 $proxy->setProxyInitializer(null);
58 $wrappedInstance = call_user_func($callback);
60 return true;
63 if (isset($this->servicesMap[$requestedName])) {
64 return $this->proxyFactory->createProxy($this->servicesMap[$requestedName], $initializer);
65 } elseif (isset($this->servicesMap[$name])) {
66 return $this->proxyFactory->createProxy($this->servicesMap[$name], $initializer);
69 throw new Exception\InvalidServiceNameException(
70 sprintf('The requested service "%s" was not found in the provided services map', $requestedName)