Completed
Push — master ( 573516...7a1ba4 )
by Iurii
04:24
created

Demo   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hookRouteList() 0 9 1
A getGenerators() 0 14 3
A getGenerator() 0 8 2
1
<?php
2
3
/**
4
 * @package Demo
5
 * @author Iurii Makukh <[email protected]>
6
 * @copyright Copyright (c) 2017, Iurii Makukh <[email protected]>
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License 3.0
8
 */
9
10
namespace gplcart\modules\demo;
11
12
use gplcart\core\Module;
13
14
/**
15
 * Main class for Demo module
16
 */
17
class Demo extends Module
18
{
19
20
    /**
21
     * Constructor
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
26
    }
27
28
    /**
29
     * Implements hook "route.list"
30
     * @param mixed $routes
31
     */
32
    public function hookRouteList(&$routes)
33
    {
34
        $routes['admin/module/settings/demo'] = array(
35
            'access' => 'module_edit',
36
            'handlers' => array(
37
                'controller' => array('gplcart\\modules\\demo\\controllers\\Settings', 'editSettings')
38
            )
39
        );
40
    }
41
42
    /**
43
     * Returns an array of available generator models
44
     * @return array
45
     */
46
    public function getGenerators()
47
    {
48
        $generators = array();
49
        foreach (glob(__DIR__ . "/models/generators/*.php") as $file) {
50
            $id = strtolower(pathinfo($file, PATHINFO_FILENAME));
51
            $instance = $this->getInstance("gplcart\\modules\\demo\\models\\generators\\$id");
52
            if ($instance instanceof \gplcart\modules\demo\models\Generator) {
53
                $generators[$id] = $instance;
54
            }
55
        }
56
57
        ksort($generators);
58
        return $generators;
59
    }
60
61
    /**
62
     * Returns a generator model instance
63
     * @param string $name
64
     * @return object|null
65
     */
66
    public function getGenerator($name)
67
    {
68
        $generators = $this->getGenerators();
69
        if (empty($generators[$name])) {
70
            return null;
71
        }
72
        return $generators[$name];
73
    }
74
75
}
76