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