| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Jose\Component\Checker; |
| 6 |
|
| 7 |
use InvalidArgumentException; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class HeaderCheckerManagerFactory |
| 13 |
{ |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
private array $checkers = []; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
private array $tokenTypes = []; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 48 |
|
| 49 |
|
| 50 |
public function add(string $alias, HeaderChecker $checker): void |
| 51 |
{ |
| 52 |
$this->checkers[$alias] = $checker; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function addTokenTypeSupport(TokenTypeSupport $tokenType): void |
| 59 |
{ |
| 60 |
$this->tokenTypes[] = $tokenType; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function aliases(): array |
| 69 |
{ |
| 70 |
return array_keys($this->checkers); |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public function all(): array |
| 79 |
{ |
| 80 |
return $this->checkers; |
| 81 |
} |
| 82 |
} |