1: | <?php
|
2: | namespace Opencart\Admin\Controller\Startup;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Error extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->registry->set('log', new \Opencart\System\Library\Log($this->config->get('config_error_filename') ?: $this->config->get('error_filename')));
|
16: |
|
17: | set_error_handler([$this, 'error']);
|
18: | set_exception_handler([$this, 'exception']);
|
19: | }
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | |
29: | |
30: |
|
31: | public function error(int $code, string $message, string $file, int $line): bool {
|
32: | switch ($code) {
|
33: | case E_NOTICE:
|
34: | case E_USER_NOTICE:
|
35: | $error = 'Notice';
|
36: | break;
|
37: | case E_WARNING:
|
38: | case E_USER_WARNING:
|
39: | $error = 'Warning';
|
40: | break;
|
41: | case E_ERROR:
|
42: | case E_USER_ERROR:
|
43: | $error = 'Fatal Error';
|
44: | break;
|
45: | default:
|
46: | $error = 'Unknown';
|
47: | break;
|
48: | }
|
49: |
|
50: | if ($this->config->get('config_error_log')) {
|
51: | $sting = 'PHP ' . $error . ': ' . $message . "\n";
|
52: | $sting .= 'File: ' . $file . "\n";
|
53: | $sting .= 'Line: ' . $line . "\n";
|
54: |
|
55: | $this->log->write($sting);
|
56: | }
|
57: |
|
58: | if ($this->config->get('config_error_display')) {
|
59: | echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
|
60: | } else {
|
61: | header('Location: ' . $this->config->get('error_page'));
|
62: | exit();
|
63: | }
|
64: |
|
65: | return true;
|
66: | }
|
67: |
|
68: | |
69: | |
70: | |
71: | |
72: | |
73: | |
74: |
|
75: | public function exception(\Throwable $e): void {
|
76: | if ($this->config->get('config_error_log')) {
|
77: | $sting = $e->getCode() . ': ' . $e->getMessage() . "\n";
|
78: | $sting .= 'File: ' . $e->getFile() . "\n";
|
79: | $sting .= 'Line: ' . $e->getLine() . "\n";
|
80: |
|
81: | $this->log->write($sting);
|
82: | }
|
83: |
|
84: | if ($this->config->get('config_error_display')) {
|
85: | echo '<b>' . $e->getMessage() . '</b>: in <b>' . $e->getFile() . '</b> on line <b>' . $e->getLine() . '</b>';
|
86: | } else {
|
87: | header('Location: ' . $this->config->get('error_page'));
|
88: | exit();
|
89: | }
|
90: | }
|
91: | }
|
92: | |