Main   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 92
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B hookRouteList() 0 26 1
A hookConstructControllerBackend() 0 4 1
A hookUserRolePermissions() 0 6 1
A setModuleAssets() 0 7 3
A getCodemirrorModule() 0 6 1
1
<?php
2
3
/**
4
 * @package Theme editor
5
 * @author Iurii Makukh
6
 * @copyright Copyright (c) 2017, Iurii Makukh
7
 * @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+
8
 */
9
10
namespace gplcart\modules\editor;
11
12
use gplcart\core\Module;
13
14
/**
15
 * Main class for Theme editor module
16
 */
17
class Main
18
{
19
20
    /**
21
     * Module class instance
22
     * @var \gplcart\core\Module $module
23
     */
24
    protected $module;
25
26
    /**
27
     * @param Module $module
28
     */
29
    public function __construct(Module $module)
30
    {
31
        $this->module = $module;
32
    }
33
34
    /**
35
     * Implements hook "route.list"
36
     * @param array $routes
37
     */
38
    public function hookRouteList(array &$routes)
39
    {
40
        $routes['admin/tool/editor'] = array(
41
            'access' => 'editor',
42
            'menu' => array(
43
                'admin' => 'Theme editor' // @text
44
            ),
45
            'handlers' => array(
46
                'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'themeEditor')
47
            )
48
        );
49
50
        $routes['admin/tool/editor/(\w+)'] = array(
51
            'access' => 'editor',
52
            'handlers' => array(
53
                'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'listEditor')
54
            )
55
        );
56
57
        $routes['admin/tool/editor/(\w+)/([^/]+)'] = array(
58
            'access' => 'editor_content',
59
            'handlers' => array(
60
                'controller' => array('gplcart\\modules\\editor\\controllers\\Editor', 'editEditor')
61
            )
62
        );
63
    }
64
65
    /**
66
     * Implements hook "construct.controller.backend"
67
     * @param \gplcart\core\controllers\backend\Controller $controller
68
     */
69
    public function hookConstructControllerBackend($controller)
70
    {
71
        $this->setModuleAssets($controller);
72
    }
73
74
    /**
75
     * Implements hook "user.role.permissions"
76
     * @param array $permissions
77
     */
78
    public function hookUserRolePermissions(array &$permissions)
79
    {
80
        $permissions['editor'] = 'Theme editor: access'; // @text
81
        $permissions['editor_edit'] = 'Theme editor: edit file'; // @text
82
        $permissions['editor_content'] = 'Theme editor: access file content'; // @text
83
    }
84
85
    /**
86
     * Sets module specific assets
87
     * @param \gplcart\core\controllers\backend\Controller $controller
88
     */
89
    protected function setModuleAssets($controller)
90
    {
91
        if ($controller->path('^admin/tool/editor') && $this->module->isEnabled('codemirror')) {
92
            $this->getCodemirrorModule()->addLibrary($controller);
93
            $controller->setJs('system/modules/editor/js/common.js');
94
        }
95
    }
96
97
    /**
98
     * Returns CodeMirror module instance
99
     * @return \gplcart\modules\codemirror\Main
100
     */
101
    protected function getCodemirrorModule()
102
    {
103
        /** @var \gplcart\modules\codemirror\Main $instance */
104
        $instance = $this->module->getInstance('codemirror');
105
        return $instance;
106
    }
107
108
}
109