-
Notifications
You must be signed in to change notification settings - Fork 30
/
AbstractConfig.php
93 lines (84 loc) · 2.53 KB
/
AbstractConfig.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* This file is part of the PPI Framework.
*
* @copyright Copyright (c) 2011-2016 Paul Dragoonis <paul@ppi.io>
* @license http://opensource.org/licenses/mit-license.php MIT
*
* @link http://www.ppi.io
*/
namespace PPI\Framework\ServiceManager\Config;
use PPI\Framework\Config\ConfigurationProviderInterface;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\ServiceManager;
use Zend\Stdlib\ArrayUtils;
/**
* AbstractConfig class.
*
* @author Vítor Brandão <vitor@ppi.io>
*/
abstract class AbstractConfig extends Config implements ConfigurationProviderInterface
{
/**
* Returns the mandatory prefix to use when using YAML.
*
* This convention is to remove the "Config" postfix from the class
* name and then lowercase and underscore the result. So:
*
* AcmeHelloConfig
*
* becomes
*
* acme_hello
*
* This can be overridden in a sub-class to specify the alias manually.
*
* @throws \BadMethodCallException When the extension name does not follow conventions
*
* @return string The alias
*/
public function getAlias()
{
$className = get_class($this);
if (substr($className, -6) != 'Config') {
throw new \BadMethodCallException('This Config class does not follow the naming convention; you must overwrite the getAlias() method.');
}
$classBaseName = substr(strrchr($className, '\\'), 1, -6);
return strtolower($classBaseName);
}
/**
* Returns the configuration reference for this component.
*
* @returns array
*/
public function getConfigurationReference()
{
return array($this->getAlias() => array());
}
/**
* @param ServiceManager $serviceManager
*
* @return array
*/
public function getParameters(ServiceManager $serviceManager)
{
$config = $serviceManager->get('Config');
return isset($config['parameters']) ? $config['parameters'] : array();
}
/**
* Process an array with the application configuration.
*
* @param array $config
* @param \Zend\ServiceManager\ServiceManager $serviceManager
*
* @return array
*/
abstract protected function processConfiguration(array $config, ServiceManager $serviceManager = null);
/**
* Merges configuration.
*/
protected function mergeConfiguration(array $defaults, array $config)
{
return ArrayUtils::merge($defaults, $config);
}
}