Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Jose\Component\Checker;
6
7 use InvalidArgumentException;
8
9 /**
10 * @see \Jose\Tests\Component\Checker\ClaimCheckerManagerFactoryTest
11 */
12 class ClaimCheckerManagerFactory
13 {
14 /**
15 * @var ClaimChecker[]
16 */
17 private array $checkers = [];
18
19 /**
20 * This method creates a Claim Checker Manager and populate it with the claim checkers found based on the alias. If
21 * the alias is not supported, an InvalidArgumentException is thrown.
22 *
23 * @param string[] $aliases
24 */
25 public function create(array $aliases): ClaimCheckerManager
26 {
27 $checkers = [];
28 foreach ($aliases as $alias) {
29 if (! isset($this->checkers[$alias])) {
30 throw new InvalidArgumentException(sprintf(
31 'The claim checker with the alias "%s" is not supported.',
32 $alias
33 ));
34 }
35 $checkers[] = $this->checkers[$alias];
36 }
37
38 return new ClaimCheckerManager($checkers);
39 }
40
41 /**
42 * This method adds a claim checker to this factory.
43 */
44 public function add(string $alias, ClaimChecker $checker): void
45 {
46 $this->checkers[$alias] = $checker;
47 }
48
49 /**
50 * Returns all claim checker aliases supported by this factory.
51 *
52 * @return string[]
53 */
54 public function aliases(): array
55 {
56 return array_keys($this->checkers);
57 }
58
59 /**
60 * Returns all claim checkers supported by this factory.
61 *
62 * @return ClaimChecker[]
63 */
64 public function all(): array
65 {
66 return $this->checkers;
67 }
68 }