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

Commit

Permalink
Merge pull request #68 from Petschko/dev
Browse files Browse the repository at this point in the history
Fixes the Weak-Warning Bug & removed unused logging
  • Loading branch information
Petschko authored Apr 15, 2019
2 parents df0de1d + b6adf9e commit a78ea29
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 39 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ All these Persons helped to create this SDK for the DHL-API:
- [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)_


## Donate

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. ^.^

## Contact

- You can E-Mail me if you have Questions or whatever (No Bug-Reporting please!): [email protected]
Expand Down
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
"authors": [
{
"name": "Peter Dragicevic",
"email": "[email protected]"
"email": "[email protected]",
"homepage": "http://petschko.org/",
"role": "developer"
}
],
"support": {
"email": "[email protected]",
"issues": "https://github.com/Petschko/dhl-php-sdk/issues",
"source": "https://github.com/Petschko/dhl-php-sdk",
"docs": "http://docs.petschko.org/dhl-php-sdk/index.html"
},
"require": {
"php": ">=5.4.0",
"php": ">=7.2.0",
"ext-soap": "*",
"ext-mbstring": "*"
},
Expand Down
3 changes: 0 additions & 3 deletions examples/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ $dhl->addShipmentOrder($shipmentOrder2); // You can add multiple shipments in on
Now you can set how the Label should get returned and some other stuff:

```php
// You can enable Logging if you want
$dhl->setLog((bool) true); // Default: false -> Off

/*
* You can set a Global response-type, which aplies to all ShipmentOrders (Response-Types defined in Shipments have more prio than this)
* Possible Values:
Expand Down
45 changes: 16 additions & 29 deletions includes/BusinessShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Authors-Website: http://petschko.org/
* Date: 26.01.2017
* Time: 15:37
* Update: 05.09.2018
* Version: 1.7.0
* Update: 15.04.2019
* Version: 1.7.1
*
* Notes: Contains all Functions/Values for DHL-Business-Shipment
*/
Expand Down Expand Up @@ -87,13 +87,6 @@ class BusinessShipment extends Version {
*/
private $test;

/**
* Contains if Log is enabled
*
* @var bool $log - Is Logging enabled
*/
private $log = false;

// Object-Fields
/**
* Contains the Credentials Object
Expand Down Expand Up @@ -283,7 +276,6 @@ public function __destruct() {
unset($this->soapClient);
unset($this->errors);
unset($this->test);
unset($this->log);
unset($this->credentials);
unset($this->shipmentDetails);
unset($this->service);
Expand Down Expand Up @@ -407,18 +399,30 @@ private function setTest($test) {
* Returns if log is enabled
*
* @return bool - Log enabled
*
* @deprecated - Removed Log-Function
*/
public function isLog() {
return $this->log;
trigger_error(
'[DHL-PHP-SDK]: ' . __CLASS__ . '->' . __METHOD__ . ' Logging has been removed',
E_USER_DEPRECATED
);

return false;
}

/**
* Set if log enabled
*
* @param bool $log - Enable log
*
* @deprecated - Removed Log-Function
*/
public function setLog($log) {
$this->log = $log;
trigger_error(
'[DHL-PHP-SDK]: ' . __CLASS__ . '->' . __METHOD__ . ' Logging has been removed',
E_USER_DEPRECATED
);
}

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

/**
* Add the Message to the Log if enabled
*
* @param string|array|object $message - Message to add to Log
* @param int $errorLevel - PHP-Error-Level (Default E_USER_NOTICE) | See: http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting
*/
private function log($message, $errorLevel = E_USER_NOTICE) {
if($this->isLog()) {
if(is_array($message) || is_object($message))
error_log(print_r($message, true), $errorLevel);
else
error_log($message, $errorLevel);
}
}

/**
* Build SOAP-Auth-Header
*
Expand Down Expand Up @@ -956,10 +945,8 @@ private function buildSoapClient() {
'trace' => 1
);

$this->log($auth_params);
$this->setSoapClient(new SoapClient($this->getAPIUrl(), $auth_params));
$this->getSoapClient()->__setSoapHeaders($header);
$this->log($this->getSoapClient());
}

/**
Expand Down
39 changes: 34 additions & 5 deletions includes/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Authors-Website: http://petschko.org/
* Date: 18.11.2016
* Time: 16:00
* Update: 05.09.2018
* Version: 1.3.3
* Update: 15.04.2019
* Version: 1.3.5
*
* Notes: Contains the DHL-Response Class, which manages the response that you get with simple getters
*/
Expand Down Expand Up @@ -317,8 +317,35 @@ public function countLabelData() {
* Check if the current Status-Code is correct and set the correct one if not
*/
private function validateStatusCode() {
if($this->getStatusCode() === 0 && $this->getStatusText() !== 'ok')
if($this->getStatusCode() === self::DHL_ERROR_NO_ERROR && $this->getStatusText() !== 'ok')
$this->setStatusCode(self::DHL_ERROR_WEAK_WARNING);

// Fix the DHL-Error Weak-Warning-Bug
if($this->countLabelData() === 1) {
// ALWAYS uses the Shipment-Response when only 1
$this->setStatusCode($this->getLabelData(0)->getStatusCode());
$this->setStatusText($this->getLabelData(0)->getStatusText());
$this->setStatusMessage($this->getLabelData(0)->getStatusMessage());
} else if($this->getStatusCode() === self::DHL_ERROR_WEAK_WARNING) {
$noError = true;

// Search in all shipments if an error/warning exists
foreach($this->getLabelData() as &$labelData) {
/**
* @var LabelData $labelData
*/
if($labelData->getStatusCode() !== self::DHL_ERROR_NO_ERROR) {
$noError = false;
break;
}
}

if($noError) {
$this->setStatusCode(self::DHL_ERROR_NO_ERROR);
$this->setStatusText('ok');
$this->setStatusMessage('Der Webservice wurde ohne Fehler ausgeführt.');
}
}
}

/**
Expand Down Expand Up @@ -370,8 +397,6 @@ private function loadResponse_v2($response) {
else
$this->setStatusMessage($response->Status->statusMessage);
}

$this->validateStatusCode();
}

// Set Manifest if exists (getManifest)
Expand Down Expand Up @@ -403,5 +428,9 @@ private function loadResponse_v2($response) {
$this->handleMultiShipments($response->ExportDocData);
else if(isset($response->ManifestState)) // 6
$this->handleMultiShipments($response->ManifestState);

// Validate the status to fix errors on the Main-Status and show weak-warnings
if($this->getStatusCode() !== self::DHL_ERROR_NOT_SET)
$this->validateStatusCode();
}
}

0 comments on commit a78ea29

Please sign in to comment.