Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Checker/IsEqualChecker.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Checker;
6
7 /**
8 * @see \Jose\Tests\Component\Checker\IsEqualCheckerTest
9 */
10 final class IsEqualChecker implements ClaimChecker, HeaderChecker
11 {
12 /**
13 * @param string $key The claim or header parameter name to check.
14 * @param mixed $value The expected value.
15 * @param bool $protectedHeaderOnly [optional] Whether the header parameter MUST be protected.
16 * This option has no effect for claim checkers.
17 */
18 public function __construct(
19 private readonly string $key,
20 private readonly mixed $value,
21 private readonly bool $protectedHeaderOnly = true
22 ) {
23 }
24
25 public function checkClaim(mixed $value): void
26 {
27 if ($value !== $this->value) {
28 throw new InvalidClaimException(sprintf('The "%s" claim is invalid.', $this->key), $this->key, $value);
29 }
30 }
31
32 public function supportedClaim(): string
33 {
34 return $this->key;
35 }
36
37 public function checkHeader(mixed $value): void
38 {
39 if ($value !== $this->value) {
40 throw new InvalidHeaderException(sprintf('The "%s" header is invalid.', $this->key), $this->key, $value);
41 }
42 }
43
44 public function supportedHeader(): string
45 {
46 return $this->key;
47 }
48
49 public function protectedHeaderOnly(): bool
50 {
51 return $this->protectedHeaderOnly;
52 }
53 }