Skip to content

Commit

Permalink
Makin encode a mutating method
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-b committed Dec 22, 2020
1 parent c44f0ed commit 9b0facc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "APNS - Apple Push Notification Service PHP client",
"type": "library",
"license": "MIT",
"version": "2.0.0",
"keywords": [
"apns",
"apns2",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Promise;

use SasaB\Apns\Provider\Certificate;
use SasaB\Apns\Provider\Trust;
use SasaB\Apns\Provider\JWT;


/**
* Created by PhpStorm.
Expand All @@ -20,9 +17,9 @@

final class Client
{
private $trust;
private Trust $trust;

private $http;
private ClientInterface $http;

private function __construct(Trust $trust, ClientInterface $http)
{
Expand Down Expand Up @@ -85,9 +82,6 @@ public static function auth(Trust $trust, array $options = []): Client
return new self($trust, new \GuzzleHttp\Client($options));
}

/**
* @return Trust|Certificate|JWT
*/
public function getTrust(): Trust
{
return $this->trust;
Expand Down
15 changes: 6 additions & 9 deletions src/Provider/Token/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public function __construct(
private \OpenSSLAsymmetricKey $pk,
)
{
['header' => $header, 'claims' => $claims] = $this->asArray();

$this->encoded = $this->encode($header, $claims);
$this->encode();
}

public function __toString(): string
Expand Down Expand Up @@ -78,9 +76,11 @@ public static function parse(string $token, Key $tokenKey): JWT
);
}

private function encode(array $header, array $claims): string
private function encode(): void
{
return \Firebase\JWT\JWT::encode($claims, $this->pk, 'ES256', null, $header);
['header' => $header, 'claims' => $claims] = $this->asArray();

$this->encoded = \Firebase\JWT\JWT::encode($claims, $this->pk, 'ES256', null, $header);
}

public function asString(): string
Expand All @@ -99,10 +99,7 @@ public function refresh(): JWT
$now = new \DateTime();
$this->iat = $now->getTimestamp();
$this->exp = $now->modify('+1 hour')->getTimestamp();

['header' => $header, 'claims' => $claims] = $this->asArray();

$this->encoded = $this->encode($header, $claims);
$this->encode();
}
return $this;
}
Expand Down

0 comments on commit 9b0facc

Please sign in to comment.