$servicesMap A map of service names to * class names of their respective classes */ public function __construct(private LazyLoadingValueHolderFactory $proxyFactory, private array $servicesMap) { } /** * {@inheritDoc} * * @param string $name * @return VirtualProxyInterface */ public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null) { if (isset($this->servicesMap[$name])) { $initializer = static function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($callback): bool { $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) ); } }