diff --git a/README.md b/README.md index 21ad00d..67db1ce 100644 --- a/README.md +++ b/README.md @@ -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!): peter@petschko.org diff --git a/composer.json b/composer.json index 013e52a..d69d4b8 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,19 @@ "authors": [ { "name": "Peter Dragicevic", - "email": "peter@petschko.org" + "email": "peter@petschko.org", + "homepage": "http://petschko.org/", + "role": "developer" } ], + "support": { + "email": "peter@petschko.org", + "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": "*" }, diff --git a/examples/getting-started.md b/examples/getting-started.md index adf9da4..63920f8 100644 --- a/examples/getting-started.md +++ b/examples/getting-started.md @@ -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: diff --git a/includes/BusinessShipment.php b/includes/BusinessShipment.php index c4852b0..db3b341 100644 --- a/includes/BusinessShipment.php +++ b/includes/BusinessShipment.php @@ -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 */ @@ -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 @@ -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); @@ -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 + ); } /** @@ -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 * @@ -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()); } /** diff --git a/includes/Response.php b/includes/Response.php index eccc956..3aba4b3 100644 --- a/includes/Response.php +++ b/includes/Response.php @@ -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 */ @@ -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.'); + } + } } /** @@ -370,8 +397,6 @@ private function loadResponse_v2($response) { else $this->setStatusMessage($response->Status->statusMessage); } - - $this->validateStatusCode(); } // Set Manifest if exists (getManifest) @@ -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(); } }