Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.

Commit a78ea29

Browse files
authored
Merge pull request #68 from Petschko/dev
Fixes the Weak-Warning Bug & removed unused logging
2 parents df0de1d + b6adf9e commit a78ea29

File tree

5 files changed

+64
-39
lines changed

5 files changed

+64
-39
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ All these Persons helped to create this SDK for the DHL-API:
7272
- [tobias-redmann](https://github.com/tobias-redmann) - For the `setFullStreet` method and the PHP-DHL-Example-Project for Version 1 _(This helped a lot to understand how the API works)_
7373

7474

75+
## Donate
76+
77+
If you like this Project may consider to [Donate](https://www.paypal.me/petschko). I usually do this Project in my spare time and it's completely free. So I appreciate anything, which helps the Project (Pull-Requests, Bug Report etc), these are more worth than Donations but I'm happy for every amount as well. ^.^
78+
7579
## Contact
7680

7781
- You can E-Mail me if you have Questions or whatever (No Bug-Reporting please!): peter@petschko.org

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@
66
"authors": [
77
{
88
"name": "Peter Dragicevic",
9-
"email": "peter@petschko.org"
9+
"email": "peter@petschko.org",
10+
"homepage": "http://petschko.org/",
11+
"role": "developer"
1012
}
1113
],
14+
"support": {
15+
"email": "peter@petschko.org",
16+
"issues": "https://github.com/Petschko/dhl-php-sdk/issues",
17+
"source": "https://github.com/Petschko/dhl-php-sdk",
18+
"docs": "http://docs.petschko.org/dhl-php-sdk/index.html"
19+
},
1220
"require": {
13-
"php": ">=5.4.0",
21+
"php": ">=7.2.0",
1422
"ext-soap": "*",
1523
"ext-mbstring": "*"
1624
},

examples/getting-started.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ $dhl->addShipmentOrder($shipmentOrder2); // You can add multiple shipments in on
306306
Now you can set how the Label should get returned and some other stuff:
307307

308308
```php
309-
// You can enable Logging if you want
310-
$dhl->setLog((bool) true); // Default: false -> Off
311-
312309
/*
313310
* You can set a Global response-type, which aplies to all ShipmentOrders (Response-Types defined in Shipments have more prio than this)
314311
* Possible Values:

includes/BusinessShipment.php

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Authors-Website: http://petschko.org/
88
* Date: 26.01.2017
99
* Time: 15:37
10-
* Update: 05.09.2018
11-
* Version: 1.7.0
10+
* Update: 15.04.2019
11+
* Version: 1.7.1
1212
*
1313
* Notes: Contains all Functions/Values for DHL-Business-Shipment
1414
*/
@@ -87,13 +87,6 @@ class BusinessShipment extends Version {
8787
*/
8888
private $test;
8989

90-
/**
91-
* Contains if Log is enabled
92-
*
93-
* @var bool $log - Is Logging enabled
94-
*/
95-
private $log = false;
96-
9790
// Object-Fields
9891
/**
9992
* Contains the Credentials Object
@@ -283,7 +276,6 @@ public function __destruct() {
283276
unset($this->soapClient);
284277
unset($this->errors);
285278
unset($this->test);
286-
unset($this->log);
287279
unset($this->credentials);
288280
unset($this->shipmentDetails);
289281
unset($this->service);
@@ -407,18 +399,30 @@ private function setTest($test) {
407399
* Returns if log is enabled
408400
*
409401
* @return bool - Log enabled
402+
*
403+
* @deprecated - Removed Log-Function
410404
*/
411405
public function isLog() {
412-
return $this->log;
406+
trigger_error(
407+
'[DHL-PHP-SDK]: ' . __CLASS__ . '->' . __METHOD__ . ' Logging has been removed',
408+
E_USER_DEPRECATED
409+
);
410+
411+
return false;
413412
}
414413

415414
/**
416415
* Set if log enabled
417416
*
418417
* @param bool $log - Enable log
418+
*
419+
* @deprecated - Removed Log-Function
419420
*/
420421
public function setLog($log) {
421-
$this->log = $log;
422+
trigger_error(
423+
'[DHL-PHP-SDK]: ' . __CLASS__ . '->' . __METHOD__ . ' Logging has been removed',
424+
E_USER_DEPRECATED
425+
);
422426
}
423427

424428
/**
@@ -908,21 +912,6 @@ private function checkRequestCount($array, $action, $maxReq = self::MAX_DHL_REQU
908912
. $action . '"! You tried to request ' . $count . ' ones');
909913
}
910914

911-
/**
912-
* Add the Message to the Log if enabled
913-
*
914-
* @param string|array|object $message - Message to add to Log
915-
* @param int $errorLevel - PHP-Error-Level (Default E_USER_NOTICE) | See: http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
916-
*/
917-
private function log($message, $errorLevel = E_USER_NOTICE) {
918-
if($this->isLog()) {
919-
if(is_array($message) || is_object($message))
920-
error_log(print_r($message, true), $errorLevel);
921-
else
922-
error_log($message, $errorLevel);
923-
}
924-
}
925-
926915
/**
927916
* Build SOAP-Auth-Header
928917
*
@@ -956,10 +945,8 @@ private function buildSoapClient() {
956945
'trace' => 1
957946
);
958947

959-
$this->log($auth_params);
960948
$this->setSoapClient(new SoapClient($this->getAPIUrl(), $auth_params));
961949
$this->getSoapClient()->__setSoapHeaders($header);
962-
$this->log($this->getSoapClient());
963950
}
964951

965952
/**

includes/Response.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Authors-Website: http://petschko.org/
88
* Date: 18.11.2016
99
* Time: 16:00
10-
* Update: 05.09.2018
11-
* Version: 1.3.3
10+
* Update: 15.04.2019
11+
* Version: 1.3.5
1212
*
1313
* Notes: Contains the DHL-Response Class, which manages the response that you get with simple getters
1414
*/
@@ -317,8 +317,35 @@ public function countLabelData() {
317317
* Check if the current Status-Code is correct and set the correct one if not
318318
*/
319319
private function validateStatusCode() {
320-
if($this->getStatusCode() === 0 && $this->getStatusText() !== 'ok')
320+
if($this->getStatusCode() === self::DHL_ERROR_NO_ERROR && $this->getStatusText() !== 'ok')
321321
$this->setStatusCode(self::DHL_ERROR_WEAK_WARNING);
322+
323+
// Fix the DHL-Error Weak-Warning-Bug
324+
if($this->countLabelData() === 1) {
325+
// ALWAYS uses the Shipment-Response when only 1
326+
$this->setStatusCode($this->getLabelData(0)->getStatusCode());
327+
$this->setStatusText($this->getLabelData(0)->getStatusText());
328+
$this->setStatusMessage($this->getLabelData(0)->getStatusMessage());
329+
} else if($this->getStatusCode() === self::DHL_ERROR_WEAK_WARNING) {
330+
$noError = true;
331+
332+
// Search in all shipments if an error/warning exists
333+
foreach($this->getLabelData() as &$labelData) {
334+
/**
335+
* @var LabelData $labelData
336+
*/
337+
if($labelData->getStatusCode() !== self::DHL_ERROR_NO_ERROR) {
338+
$noError = false;
339+
break;
340+
}
341+
}
342+
343+
if($noError) {
344+
$this->setStatusCode(self::DHL_ERROR_NO_ERROR);
345+
$this->setStatusText('ok');
346+
$this->setStatusMessage('Der Webservice wurde ohne Fehler ausgeführt.');
347+
}
348+
}
322349
}
323350

324351
/**
@@ -370,8 +397,6 @@ private function loadResponse_v2($response) {
370397
else
371398
$this->setStatusMessage($response->Status->statusMessage);
372399
}
373-
374-
$this->validateStatusCode();
375400
}
376401

377402
// Set Manifest if exists (getManifest)
@@ -403,5 +428,9 @@ private function loadResponse_v2($response) {
403428
$this->handleMultiShipments($response->ExportDocData);
404429
else if(isset($response->ManifestState)) // 6
405430
$this->handleMultiShipments($response->ManifestState);
431+
432+
// Validate the status to fix errors on the Main-Status and show weak-warnings
433+
if($this->getStatusCode() !== self::DHL_ERROR_NOT_SET)
434+
$this->validateStatusCode();
406435
}
407436
}

0 commit comments

Comments
 (0)