Skip to content

Commit 0ad73d8

Browse files
committed
always call printDebug
dont print html when debugging in console
1 parent c46625d commit 0ad73d8

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/PrestashopWebServiceLibrary.php

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class PrestashopWebServiceLibrary
2222
/** @var string PS version */
2323
protected $version;
2424

25+
/** @var boolean Are we running in a console */
26+
protected $runningInConsole;
27+
2528
/** @var array compatible versions of PrestaShop Webservice */
2629
const PS_COMPATIBLE_VERSION_MIN = '1.4.0.0';
2730
const PS_COMPATIBLE_VERSION_MAX = '1.7.99.99';
@@ -57,6 +60,8 @@ public function __construct($url, $key, $debug = true)
5760
$this->key = $key;
5861
$this->debug = $debug;
5962
$this->version = 'unknown';
63+
64+
$this->runningInConsole = app()->runningInConsole();
6065
}
6166

6267
/**
@@ -163,32 +168,39 @@ protected function executeRequest($url, $curl_params = array())
163168
}
164169
}
165170

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+
170174
$status_code = curl_getinfo($session, CURLINFO_HTTP_CODE);
171175
if ($status_code === 0) {
172176
throw new PrestaShopWebserviceException('CURL Error: '.curl_error($session));
173177
}
174178
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);
182185
}
183186
return array('status_code' => $status_code, 'response' => $body, 'header' => $header);
184187
}
185188

186189
public function printDebug($title, $content)
187190
{
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+
}
192204
}
193205

194206
public function getVersion()

0 commit comments

Comments
 (0)