proxyFactory = $proxyFactory; $this->servicesMap = $servicesMap; } /** * {@inheritDoc} * * @return \ProxyManager\Proxy\VirtualProxyInterface */ public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null) { if (isset($this->servicesMap[$name])) { $initializer = function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($callback) { $proxy->setProxyInitializer(null); $wrappedInstance = $callback(); return true; }; return $this->proxyFactory->createProxy($this->servicesMap[$name], $initializer); } throw new Exception\ServiceNotFoundException( sprintf('The requested service "%s" was not found in the provided services map', $name) ); } }