public function createInstance(Container $container, $serviceName, array $serviceConfig) { if (!isset($serviceConfig['lazy']) || !$serviceConfig['lazy']) { return $this->activator->createInstance($container, $serviceName, $serviceConfig); } $activator = $this->activator; $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory(); $proxy = $factory->createProxy($serviceConfig['class'], function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use($activator, $container, $serviceName, $serviceConfig) { $wrappedObject = $activator->createInstance($container, $serviceName, $serviceConfig); $initializer = null; return true; }); return $proxy; }
/** * Construct the ILS authenticator. * * @param ServiceManager $sm Service manager. * * @return ILSAuthenticator */ public static function getILSAuthenticator(ServiceManager $sm) { // Construct the ILS authenticator as a lazy loading value holder so that // the object is not instantiated until it is called. This helps break a // potential circular dependency with the MultiBackend driver as well as // saving on initialization costs in cases where the authenticator is not // actually utilized. $callback = function (&$wrapped, $proxy) use($sm) { // Generate wrapped object: $auth = $sm->get('VuFind\\AuthManager'); $catalog = $sm->get('VuFind\\ILSConnection'); $wrapped = new ILSAuthenticator($auth, $catalog); // Indicate that initialization is complete to avoid reinitialization: $proxy->setProxyInitializer(null); }; $factory = new \ProxyManager\Factory\LazyLoadingValueHolderFactory(); return $factory->createProxy('VuFind\\Auth\\ILSAuthenticator', $callback); }