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

Demo::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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