1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class LimeSoda_LiveGuard_Model_Config |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
const XML_PATH = 'global/limesoda/guards'; |
6
|
|
|
|
7
|
|
|
protected $_config = null; |
8
|
|
|
|
9
|
|
|
protected $_guards = null; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Returns whether the configuration node exists. |
13
|
|
|
* |
14
|
|
|
* @return bool |
15
|
|
|
*/ |
16
|
|
|
public function configExists() |
17
|
|
|
{ |
18
|
|
|
return ($this->getConfig() !== false); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Returns the configuration XML. |
23
|
|
|
* |
24
|
|
|
* @return Mage_Core_Model_Config_Element|false |
25
|
|
|
*/ |
26
|
|
|
public function getConfig() |
27
|
|
|
{ |
28
|
|
|
if ($this->_config === null) { |
29
|
|
|
$this->_config = Mage::getConfig()->getNode(self::XML_PATH); |
30
|
|
|
} |
31
|
|
|
return $this->_config; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the guards. |
36
|
|
|
* |
37
|
|
|
* @return Array an array of guards |
38
|
|
|
*/ |
39
|
|
|
public function getGuards() |
40
|
|
|
{ |
41
|
|
|
if ($this->_guards === null) { |
42
|
|
|
$environment = Mage::helper('limesoda_environmentconfiguration/current')->getEnvironmentName(); |
43
|
|
|
|
44
|
|
|
$guards = array(); |
45
|
|
|
|
46
|
|
|
foreach ($this->getConfig()->asArray() as $name => $config) { |
47
|
|
|
if (!array_key_exists('active', $config) || !array_key_exists('environments_to_omit', $config) || !array_key_exists('class', $config)) { |
48
|
|
|
throw new InvalidArgumentException("Guard '$name' misses parts of the configuration."); |
49
|
|
|
} |
50
|
|
|
if ($config['active'] === 'false' || in_array($environment, explode(',', $config['environments_to_omit']))) { |
51
|
|
|
continue; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$modelClass = $config['class']; |
55
|
|
|
$guard = Mage::getModel($modelClass); |
56
|
|
|
|
57
|
|
|
if (!($guard instanceof LimeSoda_LiveGuard_Model_GuardInterface)) { |
58
|
|
|
throw new InvalidArgumentException('Guard class doesn\'t implement the guard interface.'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$guards[] = $guard; |
62
|
|
|
} |
63
|
|
|
$this->_guards = $guards; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
return $this->_guards; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.