1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee;
13
14 use ICanBoogie\Debug;
15 use ICanBoogie\Exception;
16 use ICanBoogie\HTTP\HTTPError;
17 use ICanBoogie\Module;
18 use ICanBoogie\Operation;
19 use ICanBoogie\Route;
20
21 use Brickrouge\Document;
22
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 class Core extends \ICanBoogie\Core
42 {
43 44 45 46 47
48 static public function exception_handler(\Exception $exception)
49 {
50 global $core;
51
52 $code = $exception->getCode() ?: 500;
53 $message = $exception->getMessage();
54 $class = get_class($exception);
55
56 if (!headers_sent())
57 {
58 $normalized_message = strip_tags($message);
59 $normalized_message = str_replace(array("\r\n", "\n"), ' ', $normalized_message);
60 $normalized_message = mb_convert_encoding($normalized_message, \ICanBoogie\CHARSET, 'ASCII');
61
62 if (strlen($normalized_message) > 32)
63 {
64 $normalized_message = mb_substr($normalized_message, 0, 29) . '...';
65 }
66
67 header('HTTP/1.0 ' . $code . ' ' . $class . ': ' . $normalized_message);
68 header('X-ICanBoogie-Exception: ' . \ICanBoogie\strip_root($exception->getFile()) . '@' . $exception->getLine());
69 }
70
71 if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
72 {
73 $rc = json_encode(array('rc' => null, 'errors' => array('_base' => $message)));
74
75 header('Content-Type: application/json');
76 header('Content-Length: ' . strlen($rc));
77
78 exit($rc);
79 }
80
81 $formated_exception = Debug::format_alert($exception);
82 $reported = false;
83
84 if (!($exception instanceof HTTPError))
85 {
86 Debug::report($formated_exception);
87
88 $reported = true;
89 }
90
91 if (!headers_sent())
92 {
93 $site = isset($core->site) ? $core->site : null;
94
95 if (class_exists('Brickrouge\Document'))
96 {
97 $css = array
98 (
99 Document::resolve_url(\Brickrouge\ASSETS . 'brickrouge.css'),
100 Document::resolve_url(ASSETS . 'admin.css'),
101 Document::resolve_url(ASSETS . 'admin-more.css')
102 );
103 }
104 else
105 {
106 $css = array();
107 }
108
109 $formated_exception = require(__DIR__ . '/exception.tpl.php');
110 }
111
112 exit($formated_exception);
113 }
114
115 116 117
118 protected function lazy_get_modules()
119 {
120 $config = $this->config;
121
122 return new Modules($config['module-path'], $config['cache modules'] ? $this->vars : null);
123 }
124 }