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