|
| 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; |
| 11 | + |
| 12 | +class Config implements ConfigInterface |
| 13 | +{ |
| 14 | + /** |
| 15 | + * @var array |
| 16 | + */ |
| 17 | + protected $config = []; |
| 18 | + |
| 19 | + /** |
| 20 | + * Constructor |
| 21 | + * |
| 22 | + * @param array $config |
| 23 | + */ |
| 24 | + public function __construct($config = []) |
| 25 | + { |
| 26 | + $this->config = $config; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Configure service manager |
| 31 | + * |
| 32 | + * @param ServiceManager $serviceManager |
| 33 | + * @return ServiceManager Returns a new instance with the merged configuration. |
| 34 | + */ |
| 35 | + public function configureServiceManager(ServiceManager $serviceManager) |
| 36 | + { |
| 37 | + $config = []; |
| 38 | + $abstractFactories = isset($this->config['abstract_factories']) ? $this->config['abstract_factories'] : []; |
| 39 | + $aliases = isset($this->config['aliases']) ? $this->config['aliases'] : []; |
| 40 | + $delegators = isset($this->config['delegators']) ? $this->config['delegators'] : []; |
| 41 | + $factories = isset($this->config['factories']) ? $this->config['factories'] : []; |
| 42 | + $initializers = isset($this->config['initializers']) ? $this->config['initializers'] : []; |
| 43 | + $invokables = isset($this->config['invokables']) ? $this->config['invokables'] : []; |
| 44 | + $lazyServices = isset($this->config['lazy_services']) ? $this->config['lazy_services'] : []; |
| 45 | + $services = isset($this->config['services']) ? $this->config['services'] : []; |
| 46 | + $shared = isset($this->config['shared']) ? $this->config['shared'] : []; |
| 47 | + |
| 48 | + if (! empty($abstractFactories)) { |
| 49 | + $config['abstract_factories'] = $abstractFactories; |
| 50 | + } |
| 51 | + |
| 52 | + if (! empty($aliases)) { |
| 53 | + $config['aliases'] = $aliases; |
| 54 | + } |
| 55 | + |
| 56 | + if (! empty($delegators)) { |
| 57 | + $config['delegators'] = $delegators; |
| 58 | + } |
| 59 | + |
| 60 | + if (! empty($factories)) { |
| 61 | + $config['factories'] = $factories; |
| 62 | + } |
| 63 | + |
| 64 | + if (! empty($initializers)) { |
| 65 | + $config['initializers'] = $initializers; |
| 66 | + } |
| 67 | + |
| 68 | + if (! empty($invokables)) { |
| 69 | + $config['invokables'] = $invokables; |
| 70 | + } |
| 71 | + |
| 72 | + if (! empty($lazyServices)) { |
| 73 | + $config['lazy_services'] = $lazyServices; |
| 74 | + } |
| 75 | + |
| 76 | + if (! empty($services)) { |
| 77 | + $config['services'] = $services; |
| 78 | + } |
| 79 | + |
| 80 | + if (! empty($shared)) { |
| 81 | + $config['shared'] = $shared; |
| 82 | + } |
| 83 | + |
| 84 | + return $serviceManager->withConfig($config); |
| 85 | + } |
| 86 | +} |
0 commit comments