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

OpenCart API API documentation generated by ApiGen dev-master