@@ -14,11 +14,10 @@ class WebService{
14
14
15
15
private $ valid_key ;
16
16
17
- public function __construct ($ URL_client ){
17
+ public function __construct (){
18
18
spl_autoload_register (array ($ this , 'class_loader ' ));
19
19
}
20
20
21
-
22
21
private function HTML_entities (&$ array ){
23
22
foreach ($ array as $ k =>$ v ){
24
23
if (is_array ($ v )) {
@@ -47,13 +46,8 @@ private function write_debugger($data_array){
47
46
fclose ($ h );
48
47
}
49
48
50
-
51
-
52
- //protected function shutdown_function(){
53
49
function __destruct (){
54
50
$ error =error_get_last ();
55
- //$this->write_debugger(array('fff'));
56
- //*
57
51
if ($ error !==NULL ){
58
52
$ error_codes =array (
59
53
'1 ' =>"E_ERROR 1 A fatal run-time error, that can't be recovered from. The execution of the script is stopped immediately. " ,
@@ -74,9 +68,9 @@ function __destruct(){
74
68
//32767 E_ALL 32767 All errors and warnings, except of level E_STRICT prior to PHP 5.4.0.
75
69
);
76
70
if (!headers_sent () && isset ($ error_codes [$ error ['type ' ]])) {
77
- $ this ->write_debugger (array ("FATAL_ERROR: " , $ er , $ error ));
71
+ $ this ->write_debugger (array ("FATAL_ERROR: " , $ error ));
78
72
$ response =json_encode (array ('ResponseCode ' =>500 ,'Message ' =>$ error ));
79
- $ this -> outPut ($ response );
73
+ self :: outPut ($ response );
80
74
}else {
81
75
$ this ->write_debugger (array ("UNKNOWN ERROR: " , $ error , $ _POST ));
82
76
}
@@ -102,6 +96,7 @@ public function process_request(){
102
96
if (is_array ($ response )) {
103
97
$ this ->HTML_entities ($ response );
104
98
$ response =json_encode ($ response );
99
+
105
100
}
106
101
else {
107
102
$ ERROR ['Message ' ]='The result of the method is not an array ' ;
@@ -114,10 +109,8 @@ public function process_request(){
114
109
}
115
110
}
116
111
catch (Exception $ e ){
117
- //$this->write_debugger(array($e));
118
112
$ ERROR ['Message ' ]=$ e ->getMessage ();
119
113
}
120
-
121
114
}
122
115
else {
123
116
$ ERROR ['Message ' ]='Endpoint: ' . $ _POST ['endpoint ' ] . ', is invalid. ' ;
@@ -129,30 +122,25 @@ public function process_request(){
129
122
if ($ response =='' ){
130
123
$ response =json_encode ($ ERROR );
131
124
}
132
- $ this ->outPut ($ response );
125
+
126
+ self ::outPut ($ response );
133
127
}
134
128
135
-
136
- protected function class_loader ($ class ){
137
- /*
138
- $file='classes/' . $class . '.class.php';
139
- if(file_exists($file)){
140
- include_once $file;
141
- }else {
142
- include_once strtolower($file);
143
- }
144
- /**/
129
+ public static function Uncaught_Exception ($ exception ){
130
+ $ error =$ exception ->getMessage () . ' File: ' . $ exception ->getFile () . ' Line: ' . $ exception ->getLine ();
131
+ $ response =json_encode (array ('ResponseCode ' =>500 ,'Message ' =>$ error ));
132
+ self ::outPut ($ response );
145
133
}
146
134
147
- protected function outPut (&$ response ){
148
- /*
135
+ protected function class_loader ($ class ){}
136
+
137
+ protected static function outPut (&$ response ){
149
138
ob_clean ();
150
139
ob_start ();
151
140
header ('Content-Type: application/json ' );
152
141
header ('Content-Length: ' . strlen ($ response ));
153
142
print $ response ;
154
143
ob_end_flush ();
155
- /**/
156
144
}
157
145
}
158
146
@@ -167,20 +155,12 @@ protected function class_loader($class){
167
155
}
168
156
}
169
157
170
- protected function outPut (&$ response ){
171
- ob_clean ();
172
- ob_start ();
173
- header ('Content-Type: application/json ' );
174
- header ('Content-Length: ' . strlen ($ response ));
175
- print $ response ;
176
- ob_end_flush ();
177
- }
178
158
}
179
159
160
+ set_exception_handler ('WebService2::Uncaught_Exception ' );
180
161
181
162
$ web_service =new WebService2 ();
182
163
183
164
$ web_service ->process_request ();
184
165
185
- //
186
166
?>
0 commit comments