1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Dev |
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\dev; |
11
|
|
|
|
12
|
|
|
use gplcart\core\Module, |
13
|
|
|
gplcart\core\Library; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Main class for Dev module |
17
|
|
|
*/ |
18
|
|
|
class Dev extends Module |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Library class instance |
23
|
|
|
* @var \gplcart\core\Library |
24
|
|
|
*/ |
25
|
|
|
protected $library; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param Library $library |
29
|
|
|
*/ |
30
|
|
|
public function __construct(Library $library) |
31
|
|
|
{ |
32
|
|
|
parent::__construct(); |
33
|
|
|
|
34
|
|
|
$this->library = $library; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Implements hook "construct" |
39
|
|
|
*/ |
40
|
|
|
public function hookConstruct() |
41
|
|
|
{ |
42
|
|
|
require __DIR__ . '/vendor/kint-php/kint/init.php'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Implements hook "construct.controller" |
47
|
|
|
* @param \gplcart\core\Controller $object |
48
|
|
|
*/ |
49
|
|
|
public function hookConstructController($object) |
50
|
|
|
{ |
51
|
|
|
$settings = $this->config->module('dev'); |
52
|
|
|
|
53
|
|
|
if (!empty($settings['status']) && !empty($settings['key']) && !$object->isBackend()) { |
54
|
|
|
$object->setJsSettings('dev', array('key' => $settings['key'])); |
55
|
|
|
$object->setJs('system/modules/dev/js/common.js', array('position' => 'bottom')); |
56
|
|
|
$object->setCss('system/modules/dev/css/common.css'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Implements hook "template.output" |
62
|
|
|
* @param string $html |
63
|
|
|
* @param \gplcart\core\Controller $controller |
64
|
|
|
*/ |
65
|
|
|
public function hookTemplateOutput(&$html, $controller) |
66
|
|
|
{ |
67
|
|
|
if ($this->config->module('dev', 'status')) { |
68
|
|
|
|
69
|
|
|
$data = array( |
70
|
|
|
'time' => microtime(true) - GC_START, |
71
|
|
|
'key' => $this->config->module('dev', 'key'), |
72
|
|
|
'queries' => $this->config->getDb()->getLogs() |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$toolbar = $controller->render('dev|toolbar', $data); |
76
|
|
|
$html = substr_replace($html, $toolbar, strpos($html, '</body>'), 0); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Implements hook "library.list" |
82
|
|
|
* @param array $libraries |
83
|
|
|
*/ |
84
|
|
|
public function hookLibraryList(array &$libraries) |
85
|
|
|
{ |
86
|
|
|
$libraries['kint'] = array( |
87
|
|
|
'name' => 'Kint', |
88
|
|
|
'description' => 'A powerful and modern PHP debugging tool', |
89
|
|
|
'url' => 'https://github.com/raveren/kint', |
90
|
|
|
'download' => 'https://github.com/kint-php/kint/archive/2.0-alpha4.zip', |
91
|
|
|
'type' => 'php', |
92
|
|
|
'version' => '2.0-alpha4', |
93
|
|
|
'module' => 'dev', |
94
|
|
|
'files' => array( |
95
|
|
|
'vendor/kint-php/kint/init.php' |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Implements hook "route.list" |
102
|
|
|
* @param array $routes |
103
|
|
|
*/ |
104
|
|
|
public function hookRouteList(array &$routes) |
105
|
|
|
{ |
106
|
|
|
$routes['admin/module/settings/dev'] = array( |
107
|
|
|
'access' => '__superadmin', |
108
|
|
|
'handlers' => array( |
109
|
|
|
'controller' => array('gplcart\\modules\\dev\\controllers\\Settings', 'editSettings') |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Implements hook "module.enable.after" |
116
|
|
|
*/ |
117
|
|
|
public function hookModuleEnableAfter() |
118
|
|
|
{ |
119
|
|
|
$this->library->clearCache(); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Implements hook "module.disable.after" |
124
|
|
|
*/ |
125
|
|
|
public function hookModuleDisableAfter() |
126
|
|
|
{ |
127
|
|
|
$this->library->clearCache(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Implements hook "module.install.after" |
132
|
|
|
*/ |
133
|
|
|
public function hookModuleInstallAfter() |
134
|
|
|
{ |
135
|
|
|
$this->library->clearCache(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Implements hook "module.uninstall.after" |
140
|
|
|
*/ |
141
|
|
|
public function hookModuleUninstallAfter() |
142
|
|
|
{ |
143
|
|
|
$this->library->clearCache(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
|