1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the PPI Framework. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2011-2016 Paul Dragoonis <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT |
7
|
|
|
* |
8
|
|
|
* @link http://www.ppi.io |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PPI\Framework\ServiceManager\Factory; |
12
|
|
|
|
13
|
|
|
use Zend\ServiceManager\FactoryInterface; |
14
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
15
|
|
|
use Zend\Stdlib\ArrayUtils; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Config Factory. |
19
|
|
|
* |
20
|
|
|
* @author Vítor Brandão <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ConfigFactory implements FactoryInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Create the application configuration service. |
26
|
|
|
* |
27
|
|
|
* Retrieves the Module Manager from the service locator, and executes |
28
|
|
|
* {@link Zend\ModuleManager\ModuleManager::loadModules()}. |
29
|
|
|
* |
30
|
|
|
* It then retrieves the config listener from the module manager, and from |
31
|
|
|
* that the merged configuration. |
32
|
|
|
* |
33
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
34
|
|
|
* |
35
|
|
|
* @return array|\Traversable |
36
|
|
|
*/ |
37
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
38
|
|
|
{ |
39
|
|
|
$mm = $serviceLocator->get('ModuleManager'); |
40
|
|
|
$mm->loadModules(); |
41
|
|
|
$moduleParams = $mm->getEvent()->getParams(); |
42
|
|
|
|
43
|
|
|
$config = ArrayUtils::merge( |
44
|
|
|
$moduleParams['configListener']->getMergedConfig(false), |
45
|
|
|
$serviceLocator->get('ApplicationConfig') |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$parametersBag = $serviceLocator->get('ApplicationParameters'); |
49
|
|
|
|
50
|
|
|
$config['parameters'] = isset($config['parameters']) ? |
51
|
|
|
ArrayUtils::merge($parametersBag->all(), $config['parameters']) : |
52
|
|
|
$config['parameters'] = $parametersBag->all(); |
53
|
|
|
|
54
|
|
|
return $parametersBag->resolveArray($config); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|