Debian Codegraph @

lib/3rdParty/composer/web-token/jwt-library/Checker/HeaderCheckerManagerFactory.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\HeaderCheckerManagerFactoryTest
11 */
12 class HeaderCheckerManagerFactory
13 {
14 /**
15 * @var HeaderChecker[]
16 */
17 private array $checkers = [];
18
19 /**
20 * @var TokenTypeSupport[]
21 */
22 private array $tokenTypes = [];
23
24 /**
25 * This method creates a Header Checker Manager and populate it with the header parameter checkers found based on
26 * the alias. If the alias is not supported, an InvalidArgumentException is thrown.
27 *
28 * @param string[] $aliases
29 */
30 public function create(array $aliases): HeaderCheckerManager
31 {
32 $checkers = [];
33 foreach ($aliases as $alias) {
34 if (! isset($this->checkers[$alias])) {
35 throw new InvalidArgumentException(sprintf(
36 'The header checker with the alias "%s" is not supported.',
37 $alias
38 ));
39 }
40 $checkers[] = $this->checkers[$alias];
41 }
42
43 return new HeaderCheckerManager($checkers, $this->tokenTypes);
44 }
45
46 /**
47 * This method adds a header parameter checker to this factory. The checker is uniquely identified by an alias. This
48 * allows the same header parameter checker to be added twice (or more) using several configuration options.
49 */
50 public function add(string $alias, HeaderChecker $checker): void
51 {
52 $this->checkers[$alias] = $checker;
53 }
54
55 /**
56 * This method adds a token type support to this factory.
57 */
58 public function addTokenTypeSupport(TokenTypeSupport $tokenType): void
59 {
60 $this->tokenTypes[] = $tokenType;
61 }
62
63 /**
64 * Returns all header parameter checker aliases supported by this factory.
65 *
66 * @return string[]
67 */
68 public function aliases(): array
69 {
70 return array_keys($this->checkers);
71 }
72
73 /**
74 * Returns all header parameter checkers supported by this factory.
75 *
76 * @return HeaderChecker[]
77 */
78 public function all(): array
79 {
80 return $this->checkers;
81 }
82 }