From d907aed6c3c05817b2666af0da5216dab0ddc557 Mon Sep 17 00:00:00 2001 From: Michael Dekker Date: Mon, 10 Apr 2023 20:44:21 +0200 Subject: [PATCH] Prepare for the removal of SOAP support --- src/Entity/SOAP/Body.php | 3 ++ src/Entity/SOAP/Envelope.php | 3 ++ src/Entity/SOAP/Header.php | 3 ++ src/Entity/SOAP/Security.php | 3 ++ src/Entity/SOAP/UsernameToken.php | 2 +- src/PostNL.php | 54 ++++++++++++++++++++++++------- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/Entity/SOAP/Body.php b/src/Entity/SOAP/Body.php index 5282a445..d2a97ed1 100644 --- a/src/Entity/SOAP/Body.php +++ b/src/Entity/SOAP/Body.php @@ -31,6 +31,7 @@ use Firstred\PostNL\Service\BarcodeService; use Firstred\PostNL\Service\ConfirmingService; use Firstred\PostNL\Service\LabellingService; +use JetBrains\PhpStorm\Deprecated; /** * Class Body. @@ -38,7 +39,9 @@ * NOTE: this class has been introduced for deserializing * * @since 1.0.0 + * @deprecated 1.4.1 SOAP support is going to be removed */ +#[Deprecated] class Body extends AbstractEntity { /** @var array */ diff --git a/src/Entity/SOAP/Envelope.php b/src/Entity/SOAP/Envelope.php index 3e9a68ff..1f2da116 100644 --- a/src/Entity/SOAP/Envelope.php +++ b/src/Entity/SOAP/Envelope.php @@ -30,6 +30,7 @@ use Firstred\PostNL\Service\BarcodeService; use Firstred\PostNL\Service\ConfirmingService; use Firstred\PostNL\Service\LabellingService; +use JetBrains\PhpStorm\Deprecated; /** * Class Envelope. @@ -42,7 +43,9 @@ * NOTE: this class has been introduced for deserializing * * @since 1.0.0 + * @deprecated 1.4.1 SOAP support is going to be removed */ +#[Deprecated] class Envelope extends AbstractEntity { /** diff --git a/src/Entity/SOAP/Header.php b/src/Entity/SOAP/Header.php index f0578c76..4ab7c1d1 100644 --- a/src/Entity/SOAP/Header.php +++ b/src/Entity/SOAP/Header.php @@ -27,6 +27,7 @@ namespace Firstred\PostNL\Entity\SOAP; use Firstred\PostNL\Entity\AbstractEntity; +use JetBrains\PhpStorm\Deprecated; /** * Class Header. @@ -34,7 +35,9 @@ * NOTE: this class has been introduced for deserializing * * @since 1.0.0 + * @deprecated 1.4.1 SOAP support is going to be removed */ +#[Deprecated] class Header extends AbstractEntity { } diff --git a/src/Entity/SOAP/Security.php b/src/Entity/SOAP/Security.php index 4c24d008..7b066b39 100644 --- a/src/Entity/SOAP/Security.php +++ b/src/Entity/SOAP/Security.php @@ -27,6 +27,7 @@ namespace Firstred\PostNL\Entity\SOAP; use Firstred\PostNL\Entity\AbstractEntity; +use JetBrains\PhpStorm\Deprecated; /** * Class Security. @@ -35,7 +36,9 @@ * @method Security setUserNameToken(UsernameToken $UserNameToken) * * @since 1.0.0 + * @deprecated 1.4.1 SOAP support is going to be removed */ +#[Deprecated] class Security extends AbstractEntity { const SECURITY_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; diff --git a/src/Entity/SOAP/UsernameToken.php b/src/Entity/SOAP/UsernameToken.php index d2eefcb6..58b60740 100644 --- a/src/Entity/SOAP/UsernameToken.php +++ b/src/Entity/SOAP/UsernameToken.php @@ -39,7 +39,7 @@ * @method UsernameToken setPassword(string|null $Password = null) * * @since 1.0.0 - * @deprecated 1.4.0 + * @deprecated 1.4.0 SOAP support is going to be removed */ #[Deprecated] class UsernameToken extends AbstractEntity diff --git a/src/PostNL.php b/src/PostNL.php index 887b4f3b..7dc46600 100644 --- a/src/PostNL.php +++ b/src/PostNL.php @@ -349,11 +349,17 @@ public function __construct( public function setToken($apiKey) { if ($apiKey instanceof UsernameToken) { - $this->apiKey = $apiKey; + static::triggerDeprecation( + 'firstred/postnl-api-php', + '1.4.1', + 'Use a string for the API key instead of a `UserNameToken`' + ); + + $this->apiKey = $apiKey->getPassword(); return $this; } elseif (is_string($apiKey)) { - $this->apiKey = new UsernameToken(null, $apiKey); + $this->apiKey = $apiKey; return $this; } @@ -367,14 +373,34 @@ public function setToken($apiKey) * @return bool|string * * @since 1.0.0 + * @deprecated 1.4.1 Use `getApiKey` instead */ + #[Deprecated] public function getRestApiKey() { - if ($this->apiKey instanceof UsernameToken) { - return $this->apiKey->getPassword(); + static::triggerDeprecation( + 'firstred/postnl-api-php', + '1.4.1', + '`getRestApiKey` is deprecated, use `getApiKey` instead' + ); + + if (null == $this->apiKey) { + return false; } - return false; + return $this->apiKey; + } + + /** + * Get API Key. + * + * @return null|string + * + * @since 1.4.1 + */ + public function getApiKey() + { + return $this->apiKey; } /** @@ -383,14 +409,18 @@ public function getRestApiKey() * @return bool|UsernameToken * * @since 1.0.0 + * @deprecated 1.4.1 Use `getApiKey` instead */ + #[Deprecated] public function getToken() { - if ($this->apiKey instanceof UsernameToken) { - return $this->apiKey; - } + static::triggerDeprecation( + 'firstred/postnl-api-php', + '1.4.1', + '`getToken` is deprecated, use `getApiKey` instead' + ); - return false; + return new UsernameToken(null, $this->apiKey); } /** @@ -494,7 +524,7 @@ public function setMode($mode) if ($mode === static::MODE_SOAP) { static::triggerDeprecation( 'firstred/postnl-api-php', - '2.0.0', + '1.4.0', 'Using the SOAP API is deprecated. Please use the REST API instead.' ); } @@ -1023,7 +1053,7 @@ public function generateBarcode( if ($eps) { static::triggerDeprecation( 'firstred/postnl-api-php', - '2.0.0', + '1.4.0', 'EPS is no longer supported. Please avoid.' ); } @@ -2267,7 +2297,7 @@ public function findBarcodeSerie( } else { static::triggerDeprecation( 'firstred/postnl-api-php', - '2.0.0', + '1.4.0', 'EPS is no longer supported. Please avoid.' ); }