1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: namespace MOC\Core\Error\Type;
39: use MOC\Api;
40: use MOC\Core\Error\Reporting;
41: use MOC\Core\Journal;
42: use MOC\Generic\Common;
43:
44: 45: 46:
47: class Exception implements Common {
48:
49: private static $Singleton = null;
50:
51: 52: 53:
54: public static function InterfaceInstance() {
55: if( self::$Singleton === null ) {
56: self::$Singleton = new Exception();
57: } return self::$Singleton;
58: }
59:
60: 61: 62: 63: 64: 65:
66: public static function InterfaceDepending() {
67: return Api::Core()->Depending();
68: }
69:
70: 71: 72: 73: 74: 75:
76: public static function InterfaceChangelog() {
77: return Api::Core()->Changelog();
78: }
79:
80: 81: 82: 83: 84: 85: 86: 87:
88: public function Trigger( $Message = null, $File = null, $Line = null, $Trace = '' ) {
89: $this->Journal( trim(strip_tags(str_replace(array('<br />','<br/>','<br>'),"\n",$Message)))."\n\n".nl2br($Trace)."\n\n".'Trigger in '.$File.' at line '.$Line );
90: if( Reporting::$Display ) {
91: die( str_replace( array(
92: '{Message}'
93: ), array(
94: nl2br($Message)
95: ), $this->TemplateTrigger() )
96: );
97: } else {
98: die();
99: }
100: }
101:
102: 103: 104: 105: 106: 107: 108:
109: public function Handler( $Code, $Message, $Trace, $File, $Line ) {
110: $this->Journal( trim(strip_tags(str_replace(array('<br />','<br/>','<br>'),"\n",$Message)))."\n\n".nl2br($Trace)."\n\n".'Code ['.$Code.'] thrown in '.$File.' at line '.$Line );
111: if( Reporting::$Display ) {
112: print str_replace( array(
113: '{Code}', '{Message}', '{Trace}', '{File}', '{Position}',
114: ), array(
115: $Code, $Message, nl2br($Trace), $File, $Line
116: ), $this->TemplateHandler() );
117: }
118: }
119:
120: 121: 122:
123: private function TemplateHandler() {
124: return '<div style="color: #F00; border: 1px dotted #F00; padding: 15px; margin-top: 1px; font-family: monospace; background-color: #FFEEAA;">'.
125: '<div style="margin: 5px; margin-left: 0;">Exception</div>'.
126: '<div style="margin: 5px; margin-left: 0; font-weight: bold;">{Message}</div>'.
127: '<div style="margin: 5px;">{Trace}</div>'.
128: '<div style="margin: 5px; margin-left: 0;">Code {Code} in {File} at line {Position}</div>'.
129: '</div>';
130: }
131:
132: 133: 134:
135: private function TemplateTrigger() {
136: return '<div style="color: #F00; border: 1px dotted #F00; padding: 15px; margin-top: 1px; font-family: monospace; background-color: #FFEEAA;">'.
137: '<div style="margin: 5px; margin-left: 0; font-weight: bold;">Exception</div>'.
138: '<div style="margin: 5px;">{Message}</div>'.
139: '<div style="margin: 5px; margin-left: 0;">Expected - Execution has been stopped!</div>'.
140: '</div>';
141: }
142:
143: 144: 145:
146: private function Journal( $Content ) {
147: Journal::InterfaceInstance()->Write()->Name( __CLASS__ )->Content( $Content );
148: }
149: }
150: