Файловый менеджер - Редактировать - /var/www/html/Checker.zip
Ðазад
PK ! ���/} } HeaderCheckerManagerFactory.phpnu �[��� <?php declare(strict_types=1); namespace Jose\Component\Checker; use InvalidArgumentException; /** * @see \Jose\Tests\Component\Checker\HeaderCheckerManagerFactoryTest */ class HeaderCheckerManagerFactory { /** * @var HeaderChecker[] */ private array $checkers = []; /** * @var TokenTypeSupport[] */ private array $tokenTypes = []; /** * This method creates a Header Checker Manager and populate it with the header parameter checkers found based on * the alias. If the alias is not supported, an InvalidArgumentException is thrown. * * @param string[] $aliases */ public function create(array $aliases): HeaderCheckerManager { $checkers = []; foreach ($aliases as $alias) { if (! isset($this->checkers[$alias])) { throw new InvalidArgumentException(sprintf( 'The header checker with the alias "%s" is not supported.', $alias )); } $checkers[] = $this->checkers[$alias]; } return new HeaderCheckerManager($checkers, $this->tokenTypes); } /** * This method adds a header parameter checker to this factory. The checker is uniquely identified by an alias. This * allows the same header parameter checker to be added twice (or more) using several configuration options. */ public function add(string $alias, HeaderChecker $checker): void { $this->checkers[$alias] = $checker; } /** * This method adds a token type support to this factory. */ public function addTokenTypeSupport(TokenTypeSupport $tokenType): void { $this->tokenTypes[] = $tokenType; } /** * Returns all header parameter checker aliases supported by this factory. * * @return string[] */ public function aliases(): array { return array_keys($this->checkers); } /** * Returns all header parameter checkers supported by this factory. * * @return HeaderChecker[] */ public function all(): array { return $this->checkers; } } PK ! bB�[, , , MissingMandatoryHeaderParameterException.phpnu �[��� <?php declare(strict_types=1); namespace Jose\Component\Checker; use Exception; class MissingMandatoryHeaderParameterException extends Exception { /** * MissingMandatoryHeaderParameterException constructor. * * @param string[] $parameters */ public function __construct( string $message, private readonly array $parameters ) { parent::__construct($message); } /** * @return string[] */ public function getParameters(): array { return $this->parameters; } } PK ! U_W� ClaimCheckerManager.phpnu �[��� <?php declare(strict_types=1); namespace Jose\Component\Checker; use function array_key_exists; use function count; /** * This manager handles as many claim checkers as needed. * * @see \Jose\Tests\Component\Checker\ClaimCheckerManagerTest */ class ClaimCheckerManager { /** * @var ClaimChecker[] */ private array $checkers = []; /** * @param ClaimChecker[] $checkers */ public function __construct(iterable $checkers) { foreach ($checkers as $checker) { $this->add($checker); } } /** * This method returns all checkers handled by this manager. * * @return ClaimChecker[] */ public function getCheckers(): array { return $this->checkers; } /** * This method checks all the claims passed as argument. All claims are checked against the claim checkers. If one * fails, the InvalidClaimException is thrown. * * This method returns an array with all checked claims. It is up to the implementor to decide use the claims that * have not been checked. * * @param string[] $mandatoryClaims */ public function check(array $claims, array $mandatoryClaims = []): array { $this->checkMandatoryClaims($mandatoryClaims, $claims); $checkedClaims = []; foreach ($this->checkers as $claim => $checker) { if (array_key_exists($claim, $claims)) { $checker->checkClaim($claims[$claim]); $checkedClaims[$claim] = $claims[$claim]; } } return $checkedClaims; } private function add(ClaimChecker $checker): void { $claim = $checker->supportedClaim(); $this->checkers[$claim] = $checker; } /** * @param string[] $mandatoryClaims */ private function checkMandatoryClaims(array $mandatoryClaims, array $claims): void { if (count($mandatoryClaims) === 0) { return; } $diff = array_keys(array_diff_key(array_flip($mandatoryClaims), $claims)); if (count($diff) !== 0) { throw new MissingMandatoryClaimException(sprintf( 'The following claims are mandatory: %s.', implode(', ', $diff) ), $diff); } } } PK ! �*�e e AudienceChecker.phpnu �[��� <?php declare(strict_types=1); namespace Jose\Component\Checker; use function in_array; use function is_array; use function is_string; /** * This class is a header parameter and claim checker. When the "aud" header parameter or claim is present, it will * check if the value is within the allowed ones. */ final class AudienceChecker implements ClaimChecker, HeaderChecker { private const CLAIM_NAME = 'aud'; public function __construct( private readonly string $audience, private readonly bool $protectedHeader = false ) { } public function checkClaim(mixed $value): void { $this->checkValue($value, InvalidClaimException::class); } public function checkHeader(mixed $value): void { $this->checkValue($value, InvalidHeaderException::class); } public function supportedClaim(): string { return self::CLAIM_NAME; } public function supportedHeader(): string { return self::CLAIM_NAME; } public function protectedHeaderOnly(): bool { return $this->protectedHeader; } private function checkValue(mixed $value, string $class): void { if (is_string($value) && $value !== $this->audience) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } if (is_array($value) && ! in_array($this->audience, $value, true)) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } if (! is_array($value) && ! is_string($value)) { throw new $class('Bad audience.', self::CLAIM_NAME, $value); } } } PK ! zW�+ + "