fix travis build
[GitHub/Stricted/Domain-Control-Panel.git] / vendor / Zend / ServiceManager / Proxy / LazyServiceFactoryFactory.php
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
4 *
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
9
10 namespace Zend\ServiceManager\Proxy;
11
12 use ProxyManager\Configuration;
13 use ProxyManager\Factory\LazyLoadingValueHolderFactory;
14 use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy;
15 use Zend\ServiceManager\FactoryInterface;
16 use Zend\ServiceManager\ServiceLocatorInterface;
17 use Zend\ServiceManager\Exception;
18
19 /**
20 * Service factory responsible of instantiating {@see \Zend\ServiceManager\Proxy\LazyServiceFactory}
21 * and configuring it starting from application configuration
22 */
23 class LazyServiceFactoryFactory implements FactoryInterface
24 {
25 /**
26 * {@inheritDoc}
27 *
28 * @return \Zend\ServiceManager\Proxy\LazyServiceFactory
29 */
30 public function createService(ServiceLocatorInterface $serviceLocator)
31 {
32 $config = $serviceLocator->get('Config');
33
34 if (!isset($config['lazy_services'])) {
35 throw new Exception\InvalidArgumentException('Missing "lazy_services" config key');
36 }
37
38 $lazyServices = $config['lazy_services'];
39
40 if (!isset($lazyServices['class_map'])) {
41 throw new Exception\InvalidArgumentException('Missing "class_map" config key in "lazy_services"');
42 }
43
44 $factoryConfig = new Configuration();
45
46 if (isset($lazyServices['proxies_namespace'])) {
47 $factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
48 }
49
50 if (isset($lazyServices['proxies_target_dir'])) {
51 $factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']);
52 }
53
54 if (!isset($lazyServices['write_proxy_files']) || ! $lazyServices['write_proxy_files']) {
55 $factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
56 }
57
58 spl_autoload_register($factoryConfig->getProxyAutoloader());
59
60 return new LazyServiceFactory(new LazyLoadingValueHolderFactory($factoryConfig), $lazyServices['class_map']);
61 }
62 }