1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Flextype; |
6
|
|
|
|
7
|
|
|
use FilesystemIterator; |
8
|
|
|
use Flextype\Component\Number\Number; |
|
|
|
|
9
|
|
|
use Psr\Http\Message\ResponseInterface as Response; |
|
|
|
|
10
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request; |
|
|
|
|
11
|
|
|
use RecursiveDirectoryIterator; |
12
|
|
|
use RecursiveIteratorIterator; |
13
|
|
|
use function array_merge; |
14
|
|
|
use function file_exists; |
15
|
|
|
use function Flextype\Component\I18n\__; |
|
|
|
|
16
|
|
|
use function getenv; |
17
|
|
|
use function is_array; |
18
|
|
|
use function php_sapi_name; |
19
|
|
|
use function php_uname; |
20
|
|
|
use function realpath; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @property View $view |
24
|
|
|
* @property Router $router |
25
|
|
|
* @property Flash $flash |
26
|
|
|
*/ |
27
|
|
|
class ToolsController extends Container |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Index page |
31
|
|
|
* |
32
|
|
|
* @param Request $request PSR7 request |
33
|
|
|
* @param Response $response PSR7 response |
34
|
|
|
*/ |
35
|
|
|
public function index(Request $request, Response $response) : Response |
36
|
|
|
{ |
37
|
|
|
return $response->withRedirect($this->router->pathFor('admin.tools.information')); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Information page |
42
|
|
|
* |
43
|
|
|
* @param Request $request PSR7 request |
44
|
|
|
* @param Response $response PSR7 response |
45
|
|
|
*/ |
46
|
|
|
public function information(Request $request, Response $response) : Response |
47
|
|
|
{ |
48
|
|
|
return $this->twig->render( |
49
|
|
|
$response, |
50
|
|
|
'plugins/admin/templates/system/tools/information.html', |
51
|
|
|
[ |
52
|
|
|
'menu_item' => 'tools', |
53
|
|
|
'php_uname' => php_uname(), |
54
|
|
|
'webserver' => $_SERVER['SERVER_SOFTWARE'] ?? @getenv('SERVER_SOFTWARE'), |
55
|
|
|
'php_sapi_name' => php_sapi_name(), |
56
|
|
|
'links' => [ |
57
|
|
|
'information' => [ |
58
|
|
|
'link' => $this->router->pathFor('admin.tools.index'), |
59
|
|
|
'title' => __('admin_information'), |
|
|
|
|
60
|
|
|
'active' => true |
61
|
|
|
], |
62
|
|
|
'cache' => [ |
63
|
|
|
'link' => $this->router->pathFor('admin.tools.cache'), |
64
|
|
|
'title' => __('admin_cache'), |
65
|
|
|
|
66
|
|
|
], |
67
|
|
|
'registry' => [ |
68
|
|
|
'link' => $this->router->pathFor('admin.tools.registry'), |
69
|
|
|
'title' => __('admin_registry'), |
70
|
|
|
|
71
|
|
|
], |
72
|
|
|
], |
73
|
|
|
] |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Cache page |
79
|
|
|
* |
80
|
|
|
* @param Request $request PSR7 request |
81
|
|
|
* @param Response $response PSR7 response |
82
|
|
|
*/ |
83
|
|
|
public function cache(Request $request, Response $response) : Response |
84
|
|
|
{ |
85
|
|
|
return $this->twig->render( |
86
|
|
|
$response, |
87
|
|
|
'plugins/admin/templates/system/tools/cache.html', |
88
|
|
|
[ |
89
|
|
|
'menu_item' => 'tools', |
90
|
|
|
'doctrine_size' => Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/doctrine')), |
|
|
|
|
91
|
|
|
'glide_size' => Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/glide')), |
92
|
|
|
'twig_size' => Number::byteFormat($this->getDirectorySize(PATH['cache'] . '/twig')), |
93
|
|
|
'links' => [ |
94
|
|
|
'information' => [ |
95
|
|
|
'link' => $this->router->pathFor('admin.tools.index'), |
96
|
|
|
'title' => __('admin_information'), |
|
|
|
|
97
|
|
|
|
98
|
|
|
], |
99
|
|
|
'cache' => [ |
100
|
|
|
'link' => $this->router->pathFor('admin.tools.cache'), |
101
|
|
|
'title' => __('admin_cache'), |
102
|
|
|
'active' => true |
103
|
|
|
], |
104
|
|
|
'registry' => [ |
105
|
|
|
'link' => $this->router->pathFor('admin.tools.registry'), |
106
|
|
|
'title' => __('admin_registry'), |
107
|
|
|
|
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
'buttons' => [ |
111
|
|
|
'tools_clear_cache' => [ |
112
|
|
|
'type' => 'action', |
113
|
|
|
'id' => 'clear-cache-all', |
114
|
|
|
'link' => $this->router->pathFor('admin.tools.clearCacheAllProcess'), |
115
|
|
|
'title' => __('admin_clear_cache_all'), |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
] |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Information page |
124
|
|
|
* |
125
|
|
|
* @param Request $request PSR7 request |
126
|
|
|
* @param Response $response PSR7 response |
127
|
|
|
*/ |
128
|
|
|
public function registry(Request $request, Response $response) : Response |
129
|
|
|
{ |
130
|
|
|
return $this->twig->render( |
131
|
|
|
$response, |
132
|
|
|
'plugins/admin/templates/system/tools/registry.html', |
133
|
|
|
[ |
134
|
|
|
'menu_item' => 'tools', |
135
|
|
|
'registry_dump' => $this->dotArray($this->registry->dump()), |
136
|
|
|
'links' => [ |
137
|
|
|
'information' => [ |
138
|
|
|
'link' => $this->router->pathFor('admin.tools.index'), |
139
|
|
|
'title' => __('admin_information'), |
|
|
|
|
140
|
|
|
|
141
|
|
|
], |
142
|
|
|
'cache' => [ |
143
|
|
|
'link' => $this->router->pathFor('admin.tools.cache'), |
144
|
|
|
'title' => __('admin_cache'), |
145
|
|
|
|
146
|
|
|
], |
147
|
|
|
'registry' => [ |
148
|
|
|
'link' => $this->router->pathFor('admin.tools.registry'), |
149
|
|
|
'title' => __('admin_registry'), |
150
|
|
|
'active' => true |
151
|
|
|
], |
152
|
|
|
], |
153
|
|
|
] |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Clear cache process |
159
|
|
|
* |
160
|
|
|
* @param Request $request PSR7 request |
161
|
|
|
* @param Response $response PSR7 response |
162
|
|
|
*/ |
163
|
|
|
public function clearCacheProcess(Request $request, Response $response) : Response |
164
|
|
|
{ |
165
|
|
|
$id = $request->getParsedBody()['cache-id']; |
166
|
|
|
|
167
|
|
|
$this->cache->clear($id); |
168
|
|
|
|
169
|
|
|
$this->flash->addMessage('success', __('admin_message_cache_files_deleted')); |
|
|
|
|
170
|
|
|
|
171
|
|
|
return $response->withRedirect($this->router->pathFor('admin.tools.cache')); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Clear all cache process |
176
|
|
|
* |
177
|
|
|
* @param Request $request PSR7 request |
178
|
|
|
* @param Response $response PSR7 response |
179
|
|
|
*/ |
180
|
|
|
public function clearCacheAllProcess(Request $request, Response $response) : Response |
181
|
|
|
{ |
182
|
|
|
$this->cache->clearAll(); |
183
|
|
|
|
184
|
|
|
$this->flash->addMessage('success', __('admin_message_cache_files_deleted')); |
|
|
|
|
185
|
|
|
|
186
|
|
|
return $response->withRedirect($this->router->pathFor('admin.tools.cache')); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* _dotArray |
191
|
|
|
*/ |
192
|
|
|
private function dotArray($array, $prepend = '') : array |
193
|
|
|
{ |
194
|
|
|
$results = []; |
195
|
|
|
|
196
|
|
|
foreach ($array as $key => $value) { |
197
|
|
|
if (is_array($value) && ! empty($value)) { |
198
|
|
|
$results = array_merge($results, $this->dotArray($value, $prepend . $key . '.')); |
199
|
|
|
} else { |
200
|
|
|
$results[$prepend . $key] = $value; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
return $results; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* _getDirectorySize |
209
|
|
|
*/ |
210
|
|
|
private function getDirectorySize($path) |
211
|
|
|
{ |
212
|
|
|
$bytestotal = 0; |
213
|
|
|
$path = realpath($path); |
214
|
|
|
if ($path!==false && $path!=='' && file_exists($path)) { |
215
|
|
|
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object) { |
216
|
|
|
$bytestotal += $object->getSize(); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
return $bytestotal; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths