@@ -10,11 +10,11 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class GreaterOrEqualValidator extends Validator |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * {@inheritdoc} |
|
| 15 | - */ |
|
| 16 | - public function validate($value, $constraint): bool |
|
| 17 | - { |
|
| 18 | - return $value >= $constraint; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * {@inheritdoc} |
|
| 15 | + */ |
|
| 16 | + public function validate($value, $constraint): bool |
|
| 17 | + { |
|
| 18 | + return $value >= $constraint; |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim\Validator; |
| 6 | 6 | |
@@ -10,11 +10,11 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class LessOrEqualValidator extends Validator |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * {@inheritdoc} |
|
| 15 | - */ |
|
| 16 | - public function validate($value, $constraint): bool |
|
| 17 | - { |
|
| 18 | - return $value <= $constraint; |
|
| 19 | - } |
|
| 13 | + /** |
|
| 14 | + * {@inheritdoc} |
|
| 15 | + */ |
|
| 16 | + public function validate($value, $constraint): bool |
|
| 17 | + { |
|
| 18 | + return $value <= $constraint; |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim\Validator; |
| 6 | 6 | |
@@ -9,26 +9,26 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | abstract class Validator |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Functor method. |
|
| 14 | - * |
|
| 15 | - * @param mixed $value |
|
| 16 | - * @param mixed $constraint |
|
| 17 | - * |
|
| 18 | - * @return bool |
|
| 19 | - */ |
|
| 20 | - public function __invoke($value, $constraint): bool |
|
| 21 | - { |
|
| 22 | - return $this->validate($value, $constraint); |
|
| 23 | - } |
|
| 12 | + /** |
|
| 13 | + * Functor method. |
|
| 14 | + * |
|
| 15 | + * @param mixed $value |
|
| 16 | + * @param mixed $constraint |
|
| 17 | + * |
|
| 18 | + * @return bool |
|
| 19 | + */ |
|
| 20 | + public function __invoke($value, $constraint): bool |
|
| 21 | + { |
|
| 22 | + return $this->validate($value, $constraint); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Check whether value is valid by given constraint. |
|
| 27 | - * |
|
| 28 | - * @param mixed $value Value to assert |
|
| 29 | - * @param mixed $constraint Constraint |
|
| 30 | - * |
|
| 31 | - * @return bool True if value is valid |
|
| 32 | - */ |
|
| 33 | - abstract public function validate($value, $constraint): bool; |
|
| 25 | + /** |
|
| 26 | + * Check whether value is valid by given constraint. |
|
| 27 | + * |
|
| 28 | + * @param mixed $value Value to assert |
|
| 29 | + * @param mixed $constraint Constraint |
|
| 30 | + * |
|
| 31 | + * @return bool True if value is valid |
|
| 32 | + */ |
|
| 33 | + abstract public function validate($value, $constraint): bool; |
|
| 34 | 34 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim\Validator; |
| 6 | 6 | |
@@ -15,28 +15,28 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class NotBeforeClaim extends RegisteredClaim |
| 17 | 17 | { |
| 18 | - use NumericDateClaim; |
|
| 19 | - use ReferenceTimeValidation; |
|
| 18 | + use NumericDateClaim; |
|
| 19 | + use ReferenceTimeValidation; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Constructor. |
|
| 23 | - * |
|
| 24 | - * @param int $not_before Not before time as a unix timestamp |
|
| 25 | - */ |
|
| 26 | - public function __construct(int $not_before) |
|
| 27 | - { |
|
| 28 | - // validate that claim is before or at the constraint (reference time) |
|
| 29 | - parent::__construct(self::NAME_NOT_BEFORE, $not_before, |
|
| 30 | - new LessOrEqualValidator()); |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor. |
|
| 23 | + * |
|
| 24 | + * @param int $not_before Not before time as a unix timestamp |
|
| 25 | + */ |
|
| 26 | + public function __construct(int $not_before) |
|
| 27 | + { |
|
| 28 | + // validate that claim is before or at the constraint (reference time) |
|
| 29 | + parent::__construct(self::NAME_NOT_BEFORE, $not_before, |
|
| 30 | + new LessOrEqualValidator()); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Initialize with time set to current time. |
|
| 35 | - * |
|
| 36 | - * @return self |
|
| 37 | - */ |
|
| 38 | - public static function now(): self |
|
| 39 | - { |
|
| 40 | - return new self(time()); |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * Initialize with time set to current time. |
|
| 35 | + * |
|
| 36 | + * @return self |
|
| 37 | + */ |
|
| 38 | + public static function now(): self |
|
| 39 | + { |
|
| 40 | + return new self(time()); |
|
| 41 | + } |
|
| 42 | 42 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |
@@ -9,188 +9,188 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | trait TypedClaims |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Check whether the claim is present. |
|
| 14 | - * |
|
| 15 | - * @param string $name Claim name |
|
| 16 | - * |
|
| 17 | - * @return bool |
|
| 18 | - */ |
|
| 19 | - abstract public function has(string $name): bool; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Get the claim by name. |
|
| 23 | - * |
|
| 24 | - * @param string $name Claim name |
|
| 25 | - * |
|
| 26 | - * @return Claim |
|
| 27 | - */ |
|
| 28 | - abstract public function get(string $name): Claim; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Check whether the issuer claim is present. |
|
| 32 | - * |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function hasIssuer(): bool |
|
| 36 | - { |
|
| 37 | - return $this->has(RegisteredClaim::NAME_ISSUER); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Get the issuer claim. |
|
| 42 | - * |
|
| 43 | - * @return IssuerClaim |
|
| 44 | - */ |
|
| 45 | - public function issuer(): IssuerClaim |
|
| 46 | - { |
|
| 47 | - return self::_checkType($this->get(RegisteredClaim::NAME_ISSUER), |
|
| 48 | - IssuerClaim::class); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Check whether the subject claim is present. |
|
| 53 | - * |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 56 | - public function hasSubject(): bool |
|
| 57 | - { |
|
| 58 | - return $this->has(RegisteredClaim::NAME_SUBJECT); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get the subject claim. |
|
| 63 | - * |
|
| 64 | - * @return SubjectClaim |
|
| 65 | - */ |
|
| 66 | - public function subject(): SubjectClaim |
|
| 67 | - { |
|
| 68 | - return self::_checkType($this->get(RegisteredClaim::NAME_SUBJECT), |
|
| 69 | - SubjectClaim::class); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Check whether the audience claim is present. |
|
| 74 | - * |
|
| 75 | - * @return bool |
|
| 76 | - */ |
|
| 77 | - public function hasAudience(): bool |
|
| 78 | - { |
|
| 79 | - return $this->has(RegisteredClaim::NAME_AUDIENCE); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Get the audience claim. |
|
| 84 | - * |
|
| 85 | - * @return AudienceClaim |
|
| 86 | - */ |
|
| 87 | - public function audience(): AudienceClaim |
|
| 88 | - { |
|
| 89 | - return self::_checkType($this->get(RegisteredClaim::NAME_AUDIENCE), |
|
| 90 | - AudienceClaim::class); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Check whether the expiration time claim is present. |
|
| 95 | - * |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - public function hasExpirationTime(): bool |
|
| 99 | - { |
|
| 100 | - return $this->has(RegisteredClaim::NAME_EXPIRATION_TIME); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get the expiration time claim. |
|
| 105 | - * |
|
| 106 | - * @return ExpirationTimeClaim |
|
| 107 | - */ |
|
| 108 | - public function expirationTime(): ExpirationTimeClaim |
|
| 109 | - { |
|
| 110 | - return self::_checkType( |
|
| 111 | - $this->get(RegisteredClaim::NAME_EXPIRATION_TIME), |
|
| 112 | - ExpirationTimeClaim::class); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Check whether the not before claim is present. |
|
| 117 | - * |
|
| 118 | - * @return bool |
|
| 119 | - */ |
|
| 120 | - public function hasNotBefore(): bool |
|
| 121 | - { |
|
| 122 | - return $this->has(RegisteredClaim::NAME_NOT_BEFORE); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the not before claim. |
|
| 127 | - * |
|
| 128 | - * @return NotBeforeClaim |
|
| 129 | - */ |
|
| 130 | - public function notBefore(): NotBeforeClaim |
|
| 131 | - { |
|
| 132 | - return self::_checkType($this->get(RegisteredClaim::NAME_NOT_BEFORE), |
|
| 133 | - NotBeforeClaim::class); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Check whether the issued at claim is present. |
|
| 138 | - * |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function hasIssuedAt(): bool |
|
| 142 | - { |
|
| 143 | - return $this->has(RegisteredClaim::NAME_ISSUED_AT); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Get the issued at claim. |
|
| 148 | - * |
|
| 149 | - * @return IssuedAtClaim |
|
| 150 | - */ |
|
| 151 | - public function issuedAt(): IssuedAtClaim |
|
| 152 | - { |
|
| 153 | - return self::_checkType($this->get(RegisteredClaim::NAME_ISSUED_AT), |
|
| 154 | - IssuedAtClaim::class); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Check whether the JWT ID claim is present. |
|
| 159 | - * |
|
| 160 | - * @return bool |
|
| 161 | - */ |
|
| 162 | - public function hasJWTID(): bool |
|
| 163 | - { |
|
| 164 | - return $this->has(RegisteredClaim::NAME_JWT_ID); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get the JWT ID claim. |
|
| 169 | - * |
|
| 170 | - * @return JWTIDClaim |
|
| 171 | - */ |
|
| 172 | - public function JWTID(): JWTIDClaim |
|
| 173 | - { |
|
| 174 | - return self::_checkType($this->get(RegisteredClaim::NAME_JWT_ID), |
|
| 175 | - JWTIDClaim::class); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Check that the claim is an instance of the given class. |
|
| 180 | - * |
|
| 181 | - * @param Claim $claim Claim object |
|
| 182 | - * @param string $cls Class name |
|
| 183 | - * |
|
| 184 | - * @throws \UnexpectedValueException |
|
| 185 | - * |
|
| 186 | - * @return Claim |
|
| 187 | - */ |
|
| 188 | - private static function _checkType(Claim $claim, string $cls): Claim |
|
| 189 | - { |
|
| 190 | - if (!$claim instanceof $cls) { |
|
| 191 | - throw new \UnexpectedValueException( |
|
| 192 | - "{$cls} expected, got " . get_class($claim)); |
|
| 193 | - } |
|
| 194 | - return $claim; |
|
| 195 | - } |
|
| 12 | + /** |
|
| 13 | + * Check whether the claim is present. |
|
| 14 | + * |
|
| 15 | + * @param string $name Claim name |
|
| 16 | + * |
|
| 17 | + * @return bool |
|
| 18 | + */ |
|
| 19 | + abstract public function has(string $name): bool; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Get the claim by name. |
|
| 23 | + * |
|
| 24 | + * @param string $name Claim name |
|
| 25 | + * |
|
| 26 | + * @return Claim |
|
| 27 | + */ |
|
| 28 | + abstract public function get(string $name): Claim; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Check whether the issuer claim is present. |
|
| 32 | + * |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function hasIssuer(): bool |
|
| 36 | + { |
|
| 37 | + return $this->has(RegisteredClaim::NAME_ISSUER); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Get the issuer claim. |
|
| 42 | + * |
|
| 43 | + * @return IssuerClaim |
|
| 44 | + */ |
|
| 45 | + public function issuer(): IssuerClaim |
|
| 46 | + { |
|
| 47 | + return self::_checkType($this->get(RegisteredClaim::NAME_ISSUER), |
|
| 48 | + IssuerClaim::class); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Check whether the subject claim is present. |
|
| 53 | + * |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | + public function hasSubject(): bool |
|
| 57 | + { |
|
| 58 | + return $this->has(RegisteredClaim::NAME_SUBJECT); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get the subject claim. |
|
| 63 | + * |
|
| 64 | + * @return SubjectClaim |
|
| 65 | + */ |
|
| 66 | + public function subject(): SubjectClaim |
|
| 67 | + { |
|
| 68 | + return self::_checkType($this->get(RegisteredClaim::NAME_SUBJECT), |
|
| 69 | + SubjectClaim::class); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Check whether the audience claim is present. |
|
| 74 | + * |
|
| 75 | + * @return bool |
|
| 76 | + */ |
|
| 77 | + public function hasAudience(): bool |
|
| 78 | + { |
|
| 79 | + return $this->has(RegisteredClaim::NAME_AUDIENCE); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Get the audience claim. |
|
| 84 | + * |
|
| 85 | + * @return AudienceClaim |
|
| 86 | + */ |
|
| 87 | + public function audience(): AudienceClaim |
|
| 88 | + { |
|
| 89 | + return self::_checkType($this->get(RegisteredClaim::NAME_AUDIENCE), |
|
| 90 | + AudienceClaim::class); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Check whether the expiration time claim is present. |
|
| 95 | + * |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + public function hasExpirationTime(): bool |
|
| 99 | + { |
|
| 100 | + return $this->has(RegisteredClaim::NAME_EXPIRATION_TIME); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get the expiration time claim. |
|
| 105 | + * |
|
| 106 | + * @return ExpirationTimeClaim |
|
| 107 | + */ |
|
| 108 | + public function expirationTime(): ExpirationTimeClaim |
|
| 109 | + { |
|
| 110 | + return self::_checkType( |
|
| 111 | + $this->get(RegisteredClaim::NAME_EXPIRATION_TIME), |
|
| 112 | + ExpirationTimeClaim::class); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Check whether the not before claim is present. |
|
| 117 | + * |
|
| 118 | + * @return bool |
|
| 119 | + */ |
|
| 120 | + public function hasNotBefore(): bool |
|
| 121 | + { |
|
| 122 | + return $this->has(RegisteredClaim::NAME_NOT_BEFORE); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the not before claim. |
|
| 127 | + * |
|
| 128 | + * @return NotBeforeClaim |
|
| 129 | + */ |
|
| 130 | + public function notBefore(): NotBeforeClaim |
|
| 131 | + { |
|
| 132 | + return self::_checkType($this->get(RegisteredClaim::NAME_NOT_BEFORE), |
|
| 133 | + NotBeforeClaim::class); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Check whether the issued at claim is present. |
|
| 138 | + * |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function hasIssuedAt(): bool |
|
| 142 | + { |
|
| 143 | + return $this->has(RegisteredClaim::NAME_ISSUED_AT); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Get the issued at claim. |
|
| 148 | + * |
|
| 149 | + * @return IssuedAtClaim |
|
| 150 | + */ |
|
| 151 | + public function issuedAt(): IssuedAtClaim |
|
| 152 | + { |
|
| 153 | + return self::_checkType($this->get(RegisteredClaim::NAME_ISSUED_AT), |
|
| 154 | + IssuedAtClaim::class); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Check whether the JWT ID claim is present. |
|
| 159 | + * |
|
| 160 | + * @return bool |
|
| 161 | + */ |
|
| 162 | + public function hasJWTID(): bool |
|
| 163 | + { |
|
| 164 | + return $this->has(RegisteredClaim::NAME_JWT_ID); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get the JWT ID claim. |
|
| 169 | + * |
|
| 170 | + * @return JWTIDClaim |
|
| 171 | + */ |
|
| 172 | + public function JWTID(): JWTIDClaim |
|
| 173 | + { |
|
| 174 | + return self::_checkType($this->get(RegisteredClaim::NAME_JWT_ID), |
|
| 175 | + JWTIDClaim::class); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Check that the claim is an instance of the given class. |
|
| 180 | + * |
|
| 181 | + * @param Claim $claim Claim object |
|
| 182 | + * @param string $cls Class name |
|
| 183 | + * |
|
| 184 | + * @throws \UnexpectedValueException |
|
| 185 | + * |
|
| 186 | + * @return Claim |
|
| 187 | + */ |
|
| 188 | + private static function _checkType(Claim $claim, string $cls): Claim |
|
| 189 | + { |
|
| 190 | + if (!$claim instanceof $cls) { |
|
| 191 | + throw new \UnexpectedValueException( |
|
| 192 | + "{$cls} expected, got " . get_class($claim)); |
|
| 193 | + } |
|
| 194 | + return $claim; |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |
@@ -13,25 +13,25 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class IssuedAtClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - use NumericDateClaim; |
|
| 16 | + use NumericDateClaim; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param int $issue_time Issued at time as a unix timestamp |
|
| 22 | - */ |
|
| 23 | - public function __construct(int $issue_time) |
|
| 24 | - { |
|
| 25 | - parent::__construct(self::NAME_ISSUED_AT, $issue_time); |
|
| 26 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param int $issue_time Issued at time as a unix timestamp |
|
| 22 | + */ |
|
| 23 | + public function __construct(int $issue_time) |
|
| 24 | + { |
|
| 25 | + parent::__construct(self::NAME_ISSUED_AT, $issue_time); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Initialize with time set to current time. |
|
| 30 | - * |
|
| 31 | - * @return self |
|
| 32 | - */ |
|
| 33 | - public static function now(): self |
|
| 34 | - { |
|
| 35 | - return new self(time()); |
|
| 36 | - } |
|
| 28 | + /** |
|
| 29 | + * Initialize with time set to current time. |
|
| 30 | + * |
|
| 31 | + * @return self |
|
| 32 | + */ |
|
| 33 | + public static function now(): self |
|
| 34 | + { |
|
| 35 | + return new self(time()); |
|
| 36 | + } |
|
| 37 | 37 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |
@@ -13,23 +13,23 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class AudienceClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string ...$audiences One or more audiences |
|
| 20 | - */ |
|
| 21 | - public function __construct(string ...$audiences) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_AUDIENCE, $audiences, |
|
| 24 | - new ContainsValidator()); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string ...$audiences One or more audiences |
|
| 20 | + */ |
|
| 21 | + public function __construct(string ...$audiences) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_AUDIENCE, $audiences, |
|
| 24 | + new ContainsValidator()); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * {@inheritdoc} |
|
| 29 | - */ |
|
| 30 | - public static function fromJSONValue($value): RegisteredClaim |
|
| 31 | - { |
|
| 32 | - $value = (array) $value; |
|
| 33 | - return new self(...$value); |
|
| 34 | - } |
|
| 27 | + /** |
|
| 28 | + * {@inheritdoc} |
|
| 29 | + */ |
|
| 30 | + public static function fromJSONValue($value): RegisteredClaim |
|
| 31 | + { |
|
| 32 | + $value = (array) $value; |
|
| 33 | + return new self(...$value); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class JWTIDClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $id JWT unique identifier |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $id) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_JWT_ID, $id, new EqualsValidator()); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $id JWT unique identifier |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $id) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_JWT_ID, $id, new EqualsValidator()); |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |
@@ -14,118 +14,118 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Claim |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Claim name. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $_name; |
|
| 17 | + /** |
|
| 18 | + * Claim name. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $_name; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Claim value. |
|
| 26 | - * |
|
| 27 | - * @var mixed |
|
| 28 | - */ |
|
| 29 | - protected $_value; |
|
| 24 | + /** |
|
| 25 | + * Claim value. |
|
| 26 | + * |
|
| 27 | + * @var mixed |
|
| 28 | + */ |
|
| 29 | + protected $_value; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Claim validator. |
|
| 33 | - * |
|
| 34 | - * @var null|Validator |
|
| 35 | - */ |
|
| 36 | - protected $_validator; |
|
| 31 | + /** |
|
| 32 | + * Claim validator. |
|
| 33 | + * |
|
| 34 | + * @var null|Validator |
|
| 35 | + */ |
|
| 36 | + protected $_validator; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor. |
|
| 40 | - * |
|
| 41 | - * @param string $name Claim name |
|
| 42 | - * @param mixed $value Claim value |
|
| 43 | - * @param null|Validator $validator Claim validator or null if claim doesn't |
|
| 44 | - * provide validation |
|
| 45 | - */ |
|
| 46 | - public function __construct(string $name, $value, ?Validator $validator = null) |
|
| 47 | - { |
|
| 48 | - $this->_name = $name; |
|
| 49 | - $this->_value = $value; |
|
| 50 | - $this->_validator = $validator; |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor. |
|
| 40 | + * |
|
| 41 | + * @param string $name Claim name |
|
| 42 | + * @param mixed $value Claim value |
|
| 43 | + * @param null|Validator $validator Claim validator or null if claim doesn't |
|
| 44 | + * provide validation |
|
| 45 | + */ |
|
| 46 | + public function __construct(string $name, $value, ?Validator $validator = null) |
|
| 47 | + { |
|
| 48 | + $this->_name = $name; |
|
| 49 | + $this->_value = $value; |
|
| 50 | + $this->_validator = $validator; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Initialize from a name and a value. |
|
| 55 | - * |
|
| 56 | - * Returns a specific claim object if applicable. |
|
| 57 | - * |
|
| 58 | - * @param string $name Claim name |
|
| 59 | - * @param mixed $value Claim value |
|
| 60 | - * |
|
| 61 | - * @return Claim |
|
| 62 | - */ |
|
| 63 | - public static function fromNameAndValue(string $name, $value): Claim |
|
| 64 | - { |
|
| 65 | - if (array_key_exists($name, RegisteredClaim::MAP_NAME_TO_CLASS)) { |
|
| 66 | - $cls = RegisteredClaim::MAP_NAME_TO_CLASS[$name]; |
|
| 67 | - return $cls::fromJSONValue($value); |
|
| 68 | - } |
|
| 69 | - return new self($name, $value); |
|
| 70 | - } |
|
| 53 | + /** |
|
| 54 | + * Initialize from a name and a value. |
|
| 55 | + * |
|
| 56 | + * Returns a specific claim object if applicable. |
|
| 57 | + * |
|
| 58 | + * @param string $name Claim name |
|
| 59 | + * @param mixed $value Claim value |
|
| 60 | + * |
|
| 61 | + * @return Claim |
|
| 62 | + */ |
|
| 63 | + public static function fromNameAndValue(string $name, $value): Claim |
|
| 64 | + { |
|
| 65 | + if (array_key_exists($name, RegisteredClaim::MAP_NAME_TO_CLASS)) { |
|
| 66 | + $cls = RegisteredClaim::MAP_NAME_TO_CLASS[$name]; |
|
| 67 | + return $cls::fromJSONValue($value); |
|
| 68 | + } |
|
| 69 | + return new self($name, $value); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get the claim name. |
|
| 74 | - * |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function name(): string |
|
| 78 | - { |
|
| 79 | - return $this->_name; |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * Get the claim name. |
|
| 74 | + * |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function name(): string |
|
| 78 | + { |
|
| 79 | + return $this->_name; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get the claim value. |
|
| 84 | - * |
|
| 85 | - * @return mixed |
|
| 86 | - */ |
|
| 87 | - public function value() |
|
| 88 | - { |
|
| 89 | - return $this->_value; |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Get the claim value. |
|
| 84 | + * |
|
| 85 | + * @return mixed |
|
| 86 | + */ |
|
| 87 | + public function value() |
|
| 88 | + { |
|
| 89 | + return $this->_value; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Validate the claim against a given constraint. |
|
| 94 | - * |
|
| 95 | - * @param mixed $constraint Constraint value |
|
| 96 | - * |
|
| 97 | - * @return bool True if the claim is valid |
|
| 98 | - */ |
|
| 99 | - public function validate($constraint): bool |
|
| 100 | - { |
|
| 101 | - // if claim has no validator, consider validation failed |
|
| 102 | - if (!isset($this->_validator)) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - return $this->_validator->validate($this->_value, $constraint); |
|
| 106 | - } |
|
| 92 | + /** |
|
| 93 | + * Validate the claim against a given constraint. |
|
| 94 | + * |
|
| 95 | + * @param mixed $constraint Constraint value |
|
| 96 | + * |
|
| 97 | + * @return bool True if the claim is valid |
|
| 98 | + */ |
|
| 99 | + public function validate($constraint): bool |
|
| 100 | + { |
|
| 101 | + // if claim has no validator, consider validation failed |
|
| 102 | + if (!isset($this->_validator)) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + return $this->_validator->validate($this->_value, $constraint); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Validate the claim in a given context. |
|
| 110 | - * |
|
| 111 | - * @param ValidationContext $ctx |
|
| 112 | - * |
|
| 113 | - * @return bool True if claim is valid |
|
| 114 | - */ |
|
| 115 | - public function validateWithContext(ValidationContext $ctx): bool |
|
| 116 | - { |
|
| 117 | - // if validator has no constraint for the claim |
|
| 118 | - if (!$ctx->hasConstraint($this->_name)) { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 121 | - $constraint = $ctx->constraint($this->_name); |
|
| 122 | - // if validation context has an explicitly |
|
| 123 | - // defined validator for the claim |
|
| 124 | - if ($ctx->hasValidator($this->_name)) { |
|
| 125 | - return $ctx->validator($this->_name) |
|
| 126 | - ->validate($this->_value, $constraint); |
|
| 127 | - } |
|
| 128 | - // validate using claim's default validator |
|
| 129 | - return $this->validate($ctx->constraint($this->_name)); |
|
| 130 | - } |
|
| 108 | + /** |
|
| 109 | + * Validate the claim in a given context. |
|
| 110 | + * |
|
| 111 | + * @param ValidationContext $ctx |
|
| 112 | + * |
|
| 113 | + * @return bool True if claim is valid |
|
| 114 | + */ |
|
| 115 | + public function validateWithContext(ValidationContext $ctx): bool |
|
| 116 | + { |
|
| 117 | + // if validator has no constraint for the claim |
|
| 118 | + if (!$ctx->hasConstraint($this->_name)) { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | + $constraint = $ctx->constraint($this->_name); |
|
| 122 | + // if validation context has an explicitly |
|
| 123 | + // defined validator for the claim |
|
| 124 | + if ($ctx->hasValidator($this->_name)) { |
|
| 125 | + return $ctx->validator($this->_name) |
|
| 126 | + ->validate($this->_value, $constraint); |
|
| 127 | + } |
|
| 128 | + // validate using claim's default validator |
|
| 129 | + return $this->validate($ctx->constraint($this->_name)); |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types = 1); |
|
| 3 | +declare(strict_types=1); |
|
| 4 | 4 | |
| 5 | 5 | namespace Sop\JWX\JWT\Claim; |
| 6 | 6 | |