Completed
Push — master ( 24f445...43b2cf )
by Iurii
01:25
created

Main::hookUserRolePermissions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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\Container;
13
14
/**
15
 * Main class for File manager module
16
 */
17
class Main
18
{
19
20
    /**
21
     * Implements hook "route.list"
22
     * @param array $routes
23
     */
24
    public function hookRouteList(array &$routes)
25
    {
26
        $routes['admin/module/settings/file-manager'] = array(
27
            'access' => 'module_edit',
28
            'handlers' => array(
29
                'controller' => array('gplcart\\modules\\file_manager\\controllers\\Settings', 'editSettings')
30
            )
31
        );
32
33
        $routes['admin/tool/file-manager'] = array(
34
            'access' => 'module_file_manager',
35
            'menu' => array(
36
                'admin' => 'File manager' // @text
37
            ),
38
            'handlers' => array(
39
                'controller' => array('gplcart\\modules\\file_manager\\controllers\\FileManager', 'viewFileManager')
40
            )
41
        );
42
    }
43
44
    /**
45
     * Implements hook "validator.handlers"
46
     * @param array $handlers
47
     */
48
    public function hookValidatorHandlers(array &$handlers)
49
    {
50
        foreach (array_keys($this->getHandlers()) as $command_id) {
51
            $class = str_replace('_', '', $command_id);
52
            $handlers["file_manager_$command_id"] = array(
53
                'handlers' => array(
54
                    'validate' => array("gplcart\\modules\\file_manager\\handlers\\validators\\$class", "validate$class")
55
                ),
56
            );
57
        }
58
59
        $handlers['file_manager_settings'] = array(
60
            'handlers' => array(
61
                'validate' => array('gplcart\\modules\\file_manager\\handlers\\validators\\Settings', 'validateSettings')
62
            ),
63
        );
64
    }
65
66
    /**
67
     * Implements hook "user.role.permissions"
68
     * @param array $permissions
69
     */
70
    public function hookUserRolePermissions(array &$permissions)
71
    {
72
        $permissions['module_file_manager'] = gplcart_text('File manager: access');
73
74
        foreach ($this->getHandlers() as $command_id => $command) {
75
            $permissions["module_file_manager_$command_id"] = gplcart_text('File manager: perform command @name', array(
76
                '@name' => $command['name']));
77
        }
78
    }
79
80
    /**
81
     * Returns an array of command handlers
82
     * @return array
83
     */
84
    public function getHandlers()
85
    {
86
        return $this->getCommandModel()->getHandlers();
87
    }
88
89
    /**
90
     * Returns Command model instance
91
     * @return \gplcart\modules\file_manager\models\Command
92
     */
93
    public function getCommandModel()
94
    {
95
        /** @var \gplcart\modules\file_manager\models\Command $instance */
96
        $instance = Container::get('gplcart\\modules\\file_manager\\models\\Command');
97
        return $instance;
98
    }
99
100
}
101