diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index a55b74fa..1f9591a2 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -89,7 +89,7 @@ jobs: phpcs: runs-on: ubuntu-latest - continue-on-error: true + continue-on-error: false name: "PHPCS" steps: - name: Checkout @@ -107,7 +107,7 @@ jobs: phpstan: runs-on: ubuntu-latest - continue-on-error: true + continue-on-error: false name: "PHPStan" steps: - name: Checkout diff --git a/ApnsPHP/Push.php b/ApnsPHP/Push.php index ed9045db..ea798420 100644 --- a/ApnsPHP/Push.php +++ b/ApnsPHP/Push.php @@ -13,6 +13,7 @@ use ApnsPHP\Push\Exception; use Psr\Log\LoggerInterface; use Lcobucci\JWT\Signer\Key\InMemory; +use Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter; use Lcobucci\JWT\Signer\Ecdsa\Sha256; use Lcobucci\JWT\Configuration; @@ -475,13 +476,15 @@ protected function httpInit(): bool */ protected function getJsonWebToken(): string { - $key = InMemory::file($this->providerCertFile); - return Configuration::forUnsecuredSigner()->builder() - ->issuedBy($this->providerTeamId) - ->issuedAt(new DateTimeImmutable()) - ->withHeader('kid', $this->providerKeyId) - ->getToken(Sha256::create(), $key) - ->toString(); + $key = InMemory::file($this->providerCertFile); + $signer = new Sha256(new MultibyteStringConverter()); + $tokenBuilder = Configuration::forSymmetricSigner($signer, $key)->builder(); + + return $tokenBuilder->issuedBy($this->providerTeamId) + ->issuedAt(new DateTimeImmutable()) + ->withHeader('kid', $this->providerKeyId) + ->getToken($signer, $key) + ->toString(); } /** diff --git a/ApnsPHP/Tests/PushHttpInitTest.php b/ApnsPHP/Tests/PushHttpInitTest.php index c210ea89..9f87043c 100644 --- a/ApnsPHP/Tests/PushHttpInitTest.php +++ b/ApnsPHP/Tests/PushHttpInitTest.php @@ -68,8 +68,8 @@ public function testHttpInitSucceedsWithKey(): void ->getMock(); $token = new Plain( - new DataSet([ 'headers' ], 'eHeaders'), - new DataSet([ 'claims' ], 'eClaims'), + new DataSet([ 'headers' => 'foo' ], 'eHeaders'), + new DataSet([ 'claims' => 'bar' ], 'eClaims'), new Signature('signature', 'eSignature'), ); @@ -148,8 +148,8 @@ public function testHttpInitThrowsExceptionOnCurlSetoptFail(): void ->getMock(); $token = new Plain( - new DataSet([ 'headers' ], 'eHeaders'), - new DataSet([ 'claims' ], 'eClaims'), + new DataSet([ 'headers' => 'foo' ], 'eHeaders'), + new DataSet([ 'claims' => 'bar' ], 'eClaims'), new Signature('signature', 'eSignature'), ); diff --git a/composer.json b/composer.json index bfb9ca4a..af8a5fff 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "lib-curl": ">=7.33.0", "lib-openssl": "*", "psr/log": ">=1.1", - "lcobucci/jwt": "^4.1.5" + "lcobucci/jwt": "~4.1 || ~5.0" }, "require-dev": { "phpunit/phpunit": ">=9.0 <9.6", diff --git a/sample_push.php b/sample_push.php index 96475f7e..c3f96aeb 100644 --- a/sample_push.php +++ b/sample_push.php @@ -1,7 +1,10 @@ setSound(); // Set a custom property -$message->setCustomProperty('acme2', array('bang', 'whiz')); +$message->setCustomProperty('acme2', ['bang', 'whiz']); // Set another custom property -$message->setCustomProperty('acme3', array('bing', 'bong')); +$message->setCustomProperty('acme3', ['bing', 'bong']); // Set the expiry value to 30 seconds $message->setExpiry(30); @@ -75,5 +78,5 @@ public function log($level, $message, array $context = array()): void // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { - var_dump($aErrorQueue); + var_dump($aErrorQueue); } diff --git a/sample_push_custom.php b/sample_push_custom.php index 422b9149..1e9b40e7 100644 --- a/sample_push_custom.php +++ b/sample_push_custom.php @@ -1,7 +1,10 @@ setSound(); // Set a custom property -$message->setCustomProperty('acme2', array('bang', 'whiz')); +$message->setCustomProperty('acme2', ['bang', 'whiz']); // Set the expiry value to 30 seconds $message->setExpiry(30); @@ -61,8 +64,9 @@ public function log($level, $message, array $context = array()): void $message->setActionLocKey('Show me!'); // Set the alert-message string and variable string values to appear in place of the format specifiers. -$message->setLocKey('Hello %1$@, you have %2$@ new messages!'); // This will overwrite the text specified with setText() method. -$message->setLocArgs(array('Steve', 5)); +// This will overwrite the text specified with setText() method. +$message->setLocKey('Hello %1$@, you have %2$@ new messages!'); +$message->setLocArgs(['Steve', 5]); // Set the filename of an image file in the application bundle. $message->setLaunchImage('DefaultAlert.png'); @@ -79,5 +83,5 @@ public function log($level, $message, array $context = array()): void // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { - var_dump($aErrorQueue); + var_dump($aErrorQueue); } diff --git a/sample_push_http.php b/sample_push_http.php index a14fed84..0f866f4d 100644 --- a/sample_push_http.php +++ b/sample_push_http.php @@ -1,7 +1,10 @@ setTeamId('sgfdgfdfgd'); @@ -64,10 +67,10 @@ public function log($level, $message, array $context = array()): void $message->setSound(); // Set a custom property -$message->setCustomProperty('acme2', array('bang', 'whiz')); +$message->setCustomProperty('acme2', ['bang', 'whiz']); // Set another custom property -$message->setCustomProperty('acme3', array('bing', 'bong')); +$message->setCustomProperty('acme3', ['bing', 'bong']); // Set the expiry value to 30 seconds $message->setExpiry(30); @@ -84,5 +87,5 @@ public function log($level, $message, array $context = array()): void // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { - var_dump($aErrorQueue); + var_dump($aErrorQueue); } diff --git a/sample_push_many.php b/sample_push_many.php index 48876e0e..653f515b 100644 --- a/sample_push_many.php +++ b/sample_push_many.php @@ -1,7 +1,10 @@ connect(); for ($i = 1; $i <= 10; $i++) { - // Instantiate a new Message with a single recipient - $message = new \ApnsPHP\Message($i == 5 ? INVALID_TOKEN : VALID_TOKEN); + // Instantiate a new Message with a single recipient + $message = new \ApnsPHP\Message($i == 5 ? INVALID_TOKEN : VALID_TOKEN); - // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method - // over a ApnsPHP_Message object retrieved with the getErrors() message. - $message->setCustomIdentifier(sprintf("Message-Badge-%03d", $i)); + // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method + // over a ApnsPHP_Message object retrieved with the getErrors() message. + $message->setCustomIdentifier(sprintf("Message-Badge-%03d", $i)); - // Set badge icon to "3" - $message->setBadge($i); + // Set badge icon to "3" + $message->setBadge($i); - // Add the message to the message queue - $push->add($message); + // Add the message to the message queue + $push->add($message); } // Send all messages in the message queue @@ -68,5 +71,5 @@ public function log($level, $message, array $context = array()): void // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { - var_dump($aErrorQueue); + var_dump($aErrorQueue); } diff --git a/sample_push_safari.php b/sample_push_safari.php index 0e41bcbc..fad42a75 100644 --- a/sample_push_safari.php +++ b/sample_push_safari.php @@ -1,7 +1,10 @@ setAction('View'); -// Set an array of values that are paired with the placeholders inside the urlFormatString value of your website.json file -$message->setUrlArgs(array('boarding', 'A998')); +// Set an array of values that are paired with the placeholders inside the urlFormatString value +// of your website.json file +$message->setUrlArgs(['boarding', 'A998']); // Add the message to the message queue $push->add($message); @@ -66,5 +70,5 @@ public function log($level, $message, array $context = array()): void // Examine the error message container $aErrorQueue = $push->getErrors(); if (!empty($aErrorQueue)) { - var_dump($aErrorQueue); + var_dump($aErrorQueue); }