From 5f922239cf85494910daace47bf2d687873ca2e6 Mon Sep 17 00:00:00 2001 From: Eric Stern Date: Wed, 5 Apr 2023 15:22:13 -0700 Subject: [PATCH] Avoid excessively bloated info if printing keys or containers --- src/JWT.php | 11 +++++++++++ src/KeyContainer.php | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/JWT.php b/src/JWT.php index 4de393c..cc02eb2 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -211,4 +211,15 @@ private static function b64encode(array $data): string } return rtrim(strtr(base64_encode($json), '+/', '-_'), '='); } // b64encode + + public function __debugInfo(): array + { + return [ + 'headers' => $this->headers, + 'claims' => $this->claims, + 'signature' => isset($this->signature) ? $this->signature : '(not signed)', + 'verified' => $this->is_verified, + 'keyContainer' => isset($this->keys) ? '(set)' : '(not set)', + ]; + } } diff --git a/src/KeyContainer.php b/src/KeyContainer.php index a65412b..d582b92 100644 --- a/src/KeyContainer.php +++ b/src/KeyContainer.php @@ -52,4 +52,14 @@ public function getKey($id = null): array list($alg, $secret) = $this->keys[$id]; return [$alg, $secret, $id]; } + + public function __debugInfo(): array + { + return [ + 'keys' => array_values(array_map(function ($keyInfo, $id) { + return ['id' => $id, 'alg' => $keyInfo[0]]; + }, $this->keys, array_keys($this->keys))), + 'default' => $this->default, + ]; + } }