proxyFactory = $proxyFactory; $this->servicesMap = $servicesMap; } /** * {@inheritDoc} * * @return object|\ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */ public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback) { $initializer = function (& $wrappedInstance, LazyLoadingInterface $proxy) use ($callback) { $proxy->setProxyInitializer(null); $wrappedInstance = call_user_func($callback); return true; }; if (isset($this->servicesMap[$requestedName])) { return $this->proxyFactory->createProxy($this->servicesMap[$requestedName], $initializer); } elseif (isset($this->servicesMap[$name])) { return $this->proxyFactory->createProxy($this->servicesMap[$name], $initializer); } throw new Exception\InvalidServiceNameException( sprintf('The requested service "%s" was not found in the provided services map', $requestedName) ); } }