/**
  * {@inheritDoc}
  *
  * @return \Zend\ServiceManager\Proxy\LazyServiceFactory
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config');
     if (!isset($config['lazy_services'])) {
         throw new Exception\InvalidArgumentException('Missing "lazy_services" config key');
     }
     $lazyServices = $config['lazy_services'];
     if (!isset($lazyServices['class_map'])) {
         throw new Exception\InvalidArgumentException('Missing "class_map" config key in "lazy_services"');
     }
     $factoryConfig = new Configuration();
     if (isset($lazyServices['proxies_target_dir'])) {
         $factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']);
     }
     if (!isset($lazyServices['write_proxy_files']) || !$lazyServices['write_proxy_files']) {
         $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     if (isset($lazyServices['auto_generate_proxies'])) {
         $factoryConfig->setAutoGenerateProxies($lazyServices['auto_generate_proxies']);
         // register the proxy autoloader if the proxies already exist
         if (!$lazyServices['auto_generate_proxies']) {
             spl_autoload_register($factoryConfig->getProxyAutoloader());
             $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
         }
     }
     //if (!isset($lazyServicesConfig['runtime_evaluate_proxies']))
     if (isset($lazyServices['proxies_namespace'])) {
         $factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
     }
     return new LazyServiceFactory(new LazyLoadingValueHolderFactory($factoryConfig), $lazyServices['class_map']);
 }
 private function createProxyManager()
 {
     if ($this->proxyManager !== null) {
         return;
     }
     if (!class_exists('ProxyManager\\Configuration')) {
         throw new \RuntimeException('The ocramius/proxy-manager library is not installed. Lazy injection requires that library to be installed with Composer in order to work. Run "composer require ocramius/proxy-manager:~0.3".');
     }
     $config = new Configuration();
     /**
      * @todo useless since ProxyManager 0.5, line kept for compatibility with 0.3 and 0.4 which are
      * the only versions that work with PHP < 5.3.23
      * Remove when support for PHP 5.3 is dropped
      */
     $config->setAutoGenerateProxies(true);
     if ($this->writeProxiesToFile) {
         $config->setProxiesTargetDir($this->proxyDirectory);
         spl_autoload_register($config->getProxyAutoloader());
     } else {
         $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     $this->proxyManager = new LazyLoadingValueHolderFactory($config);
 }
Beispiel #3
0
 /**
  * @return LazyLoadingValueHolderFactory
  */
 private function buildProxyFactory()
 {
     $config = new Configuration();
     // TODO useless since ProxyManager 0.5, line kept for compatibility with previous versions
     $config->setAutoGenerateProxies(true);
     if ($this->writeProxiesToFile) {
         $config->setProxiesTargetDir($this->proxyDirectory);
         spl_autoload_register($config->getProxyAutoloader());
     } else {
         $config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
     }
     return new LazyLoadingValueHolderFactory($config);
 }