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 Error 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 Error();
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: public function Trigger( $Message = null, $File = null, $Line = null ) {
88: $this->Journal( trim(strip_tags(str_replace(array('<br />','<br/>','<br>'),"\n",$Message)))."\n\n".'Trigger in '.$File.' at line '.$Line );
89: if( Reporting::$Display ) {
90: print str_replace( array(
91: '{Message}',
92: ), array(
93: $Message
94: ), $this->TemplateTrigger() );
95: }
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105: 106: 107:
108: public function Handler( $Code, $Message, $File, $Line ) {
109: if( !Reporting::$Debug ) {
110: if( in_array( $Code, array( 8192, 2048, 8 ) ) ) {
111: return null;
112: }
113: }
114:
115: if( $Code == 2 && strpos( $Message, 'No tuples available at this result index' ) !== false ) {
116: return null;
117: }
118: $this->Journal( trim(strip_tags(str_replace(array('<br />','<br/>','<br>'),"\n",$Message)))."\n\n".'Code ['.$Code.'] thrown in '.$File.' at line '.$Line );
119: if( Reporting::$Display ) {
120: print str_replace( array(
121: '{Code}', '{Message}', '{File}', '{Line}',
122: ), array(
123: $Code, $Message, $File, $Line
124: ), $this->TemplateHandler() );
125: }
126: }
127:
128: 129: 130:
131: private function TemplateHandler() {
132: return '<div style="color: #F00; border: 1px dotted #F00; padding: 15px; margin-top: 1px; font-family: monospace; background-color: #FFEEAA;">'.
133: '<div style="margin: 5px; margin-left: 0;">Runtime-Error</div>'.
134: '<div style="margin: 5px; margin-left: 0; font-weight: bold;">{Message}</div>'.
135: '<div style="margin: 5px; margin-left: 0;">Code {Code} in {File} at line {Line}</div>'.
136: '</div>';
137: }
138:
139: 140: 141:
142: private function TemplateTrigger() {
143: return '<div style="color: #F00; border: 1px dotted #F00; padding: 15px; margin-top: 1px; font-family: monospace; background-color: #FFEEAA;">'.
144: '<div style="margin: 5px; margin-left: 0; font-weight: bold;">Error</div>'.
145: '<div style="margin: 5px;">{Message}</div>'.
146: '<div style="margin: 5px; margin-left: 0;">Expected - Execution has been continued!</div>'.
147: '</div>';
148: }
149:
150: 151: 152:
153: private function Journal( $Content ) {
154: Journal::InterfaceInstance()->Write()->Name( __CLASS__ )->Content( $Content );
155: }
156: }
157: