@@ -22,6 +22,9 @@ class PrestashopWebServiceLibrary
22
22
/** @var string PS version */
23
23
protected $ version ;
24
24
25
+ /** @var boolean Are we running in a console */
26
+ protected $ runningInConsole ;
27
+
25
28
/** @var array compatible versions of PrestaShop Webservice */
26
29
const PS_COMPATIBLE_VERSION_MIN = '1.4.0.0 ' ;
27
30
const PS_COMPATIBLE_VERSION_MAX = '1.7.99.99 ' ;
@@ -57,6 +60,8 @@ public function __construct($url, $key, $debug = true)
57
60
$ this ->key = $ key ;
58
61
$ this ->debug = $ debug ;
59
62
$ this ->version = 'unknown ' ;
63
+
64
+ $ this ->runningInConsole = app ()->runningInConsole ();
60
65
}
61
66
62
67
/**
@@ -163,32 +168,39 @@ protected function executeRequest($url, $curl_params = array())
163
168
}
164
169
}
165
170
166
- if ($ this ->debug ) {
167
- $ this ->printDebug ('HTTP REQUEST HEADER ' , curl_getinfo ($ session , CURLINFO_HEADER_OUT ));
168
- $ this ->printDebug ('HTTP RESPONSE HEADER ' , $ header );
169
- }
171
+ $ this ->printDebug ('HTTP REQUEST HEADER ' , curl_getinfo ($ session , CURLINFO_HEADER_OUT ));
172
+ $ this ->printDebug ('HTTP RESPONSE HEADER ' , $ header );
173
+
170
174
$ status_code = curl_getinfo ($ session , CURLINFO_HTTP_CODE );
171
175
if ($ status_code === 0 ) {
172
176
throw new PrestaShopWebserviceException ('CURL Error: ' .curl_error ($ session ));
173
177
}
174
178
curl_close ($ session );
175
- if ($ this ->debug ) {
176
- if ($ curl_params [CURLOPT_CUSTOMREQUEST ] == 'PUT ' || $ curl_params [CURLOPT_CUSTOMREQUEST ] == 'POST ' ) {
177
- $ this ->printDebug ('XML SENT ' , urldecode ($ curl_params [CURLOPT_POSTFIELDS ]));
178
- }
179
- if ($ curl_params [CURLOPT_CUSTOMREQUEST ] != 'DELETE ' && $ curl_params [CURLOPT_CUSTOMREQUEST ] != 'HEAD ' ) {
180
- $ this ->printDebug ('RETURN HTTP BODY ' , $ body );
181
- }
179
+
180
+ if ($ curl_params [CURLOPT_CUSTOMREQUEST ] == 'PUT ' || $ curl_params [CURLOPT_CUSTOMREQUEST ] == 'POST ' ) {
181
+ $ this ->printDebug ('XML SENT ' , urldecode ($ curl_params [CURLOPT_POSTFIELDS ]));
182
+ }
183
+ if ($ curl_params [CURLOPT_CUSTOMREQUEST ] != 'DELETE ' && $ curl_params [CURLOPT_CUSTOMREQUEST ] != 'HEAD ' ) {
184
+ $ this ->printDebug ('RETURN HTTP BODY ' , $ body );
182
185
}
183
186
return array ('status_code ' => $ status_code , 'response ' => $ body , 'header ' => $ header );
184
187
}
185
188
186
189
public function printDebug ($ title , $ content )
187
190
{
188
- echo '<div style="display:table;background:#CCC;font-size:8pt;padding:7px"> ' ;
189
- echo '<h6 style="font-size:9pt;margin:0"> ' .$ title .'</h6> ' ;
190
- echo '<pre> ' .htmlentities ($ content ).'</pre> ' ;
191
- echo '</div> ' ;
191
+ if ($ this ->debug ) {
192
+ if ($ this ->runningInConsole ) {
193
+ echo 'START ' .$ title ."\n" ;
194
+ echo $ content . "\n" ;
195
+ echo 'END ' .$ title ."\n" ;
196
+ echo "\n" ;
197
+ } else {
198
+ echo '<div style="display:table;background:#CCC;font-size:8pt;padding:7px"> ' ;
199
+ echo '<h6 style="font-size:9pt;margin:0"> ' .$ title .'</h6> ' ;
200
+ echo '<pre> ' .htmlentities ($ content ).'</pre> ' ;
201
+ echo '</div> ' ;
202
+ }
203
+ }
192
204
}
193
205
194
206
public function getVersion ()
0 commit comments