Completed
Push — master ( 400760...908c1f )
by Iurii
04:31
created

Module::getModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package File manager
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 GPL-3.0+
8
 */
9
10
namespace gplcart\modules\file_manager;
11
12
use gplcart\core\Config,
13
    gplcart\core\Container;
14
15
/**
16
 * Main class for File manager module
17
 */
18
class Module
19
{
20
21
    /**
22
     * Config class instance
23
     * @var \gplcart\core\Config $config
24
     */
25
    protected $config;
26
27
    /**
28
     * @param Config $config
29
     */
30
    public function __construct(Config $config)
31
    {
32
        $this->config = $config;
33
    }
34
35
    /**
36
     * Implements hook "route.list"
37
     * @param array $routes
38
     */
39
    public function hookRouteList(array &$routes)
40
    {
41
        $routes['admin/module/settings/file-manager'] = array(
42
            'access' => 'module_edit',
43
            'handlers' => array(
44
                'controller' => array('gplcart\\modules\\file_manager\\controllers\\Settings', 'editSettings')
45
            )
46
        );
47
48
        $routes['admin/tool/file-manager'] = array(
49
            'access' => 'module_file_manager',
50
            'menu' => array('admin' => /* @text */'File manager'),
51
            'handlers' => array(
52
                'controller' => array('gplcart\\modules\\file_manager\\controllers\\FileManager', 'viewFileManager')
53
            )
54
        );
55
    }
56
57
    /**
58
     * Implements hook "validator.handlers"
59
     * @param array $handlers
60
     */
61
    public function hookValidatorHandlers(array &$handlers)
62
    {
63
        foreach (array_keys($this->getModel()->getHandlers()) as $command_id) {
64
            $class = str_replace('_', '', $command_id);
65
            $handlers["file_manager_$command_id"] = array(
66
                'handlers' => array(
67
                    'validate' => array("gplcart\\modules\\file_manager\\handlers\\validators\\$class", "validate$class")
68
                ),
69
            );
70
        }
71
72
        $handlers['file_manager_settings'] = array(
73
            'handlers' => array(
74
                'validate' => array('gplcart\\modules\\file_manager\\handlers\\validators\\Settings', 'validateSettings')
75
            ),
76
        );
77
    }
78
79
    /**
80
     * Implements hook "user.role.permissions"
81
     * @param array $permissions
82
     */
83
    public function hookUserRolePermissions(array &$permissions)
84
    {
85
        $permissions['module_file_manager'] = $this->getLanguage()->text('File manager: access');
86
87
        foreach ($this->getModel()->getHandlers() as $command_id => $command) {
88
            $permissions["module_file_manager_$command_id"] = $this->getLanguage()->text('File manager: perform command @name', array('@name' => $command['name']));
89
        }
90
    }
91
92
    /**
93
     * Implements hook "module.install.before"
94
     * @param null|string $result
95
     */
96
    public function hookModuleInstallBefore(&$result)
97
    {
98
        if (!class_exists('ZipArchive')) {
99
            $result = $this->getLanguage()->text('Class ZipArchive does not exist');
100
        }
101
    }
102
103
    /**
104
     * Implements hook "module.uninstall.after"
105
     */
106
    public function hookModuleUninstallAfter()
107
    {
108
        foreach (array_keys($this->config->select()) as $key) {
109
            if (strpos($key, 'module_file_manager_') === 0) {
110
                $this->config->reset($key);
111
            }
112
        }
113
    }
114
115
    /**
116
     * Returns Command model instance
117
     * @return \gplcart\modules\file_manager\models\Command
118
     */
119
    protected function getModel()
120
    {
121
        return Container::get('gplcart\\modules\\file_manager\\models\\Command');
122
    }
123
124
    /**
125
     * Language model class instance
126
     * @return \gplcart\core\modules\Language
127
     */
128
    protected function getLanguage()
129
    {
130
        return Container::get('gplcart\\core\\modules\\Language');
131
    }
132
133
}
134