LimeSoda_LiveGuard_Model_Config::configExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class LimeSoda_LiveGuard_Model_Config
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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