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