@@ -10,12 +10,12 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class LessOrEqualValidator extends Validator |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * |
|
| 15 | - * {@inheritdoc} |
|
| 16 | - */ |
|
| 17 | - public function validate($value, $constraint): bool |
|
| 18 | - { |
|
| 19 | - return $value <= $constraint; |
|
| 20 | - } |
|
| 13 | + /** |
|
| 14 | + * |
|
| 15 | + * {@inheritdoc} |
|
| 16 | + */ |
|
| 17 | + public function validate($value, $constraint): bool |
|
| 18 | + { |
|
| 19 | + return $value <= $constraint; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -9,12 +9,12 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class LessValidator extends Validator |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * |
|
| 14 | - * {@inheritdoc} |
|
| 15 | - */ |
|
| 16 | - public function validate($value, $constraint): bool |
|
| 17 | - { |
|
| 18 | - return $value < $constraint; |
|
| 19 | - } |
|
| 12 | + /** |
|
| 13 | + * |
|
| 14 | + * {@inheritdoc} |
|
| 15 | + */ |
|
| 16 | + public function validate($value, $constraint): bool |
|
| 17 | + { |
|
| 18 | + return $value < $constraint; |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -9,12 +9,12 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class EqualsValidator extends Validator |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * |
|
| 14 | - * {@inheritdoc} |
|
| 15 | - */ |
|
| 16 | - public function validate($value, $constraint): bool |
|
| 17 | - { |
|
| 18 | - return $value == $constraint; |
|
| 19 | - } |
|
| 12 | + /** |
|
| 13 | + * |
|
| 14 | + * {@inheritdoc} |
|
| 15 | + */ |
|
| 16 | + public function validate($value, $constraint): bool |
|
| 17 | + { |
|
| 18 | + return $value == $constraint; |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class GreaterOrEqualValidator extends Validator |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * |
|
| 15 | - * {@inheritdoc} |
|
| 16 | - */ |
|
| 17 | - public function validate($value, $constraint): bool |
|
| 18 | - { |
|
| 19 | - return $value >= $constraint; |
|
| 20 | - } |
|
| 13 | + /** |
|
| 14 | + * |
|
| 15 | + * {@inheritdoc} |
|
| 16 | + */ |
|
| 17 | + public function validate($value, $constraint): bool |
|
| 18 | + { |
|
| 19 | + return $value >= $constraint; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -14,115 +14,115 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Claim |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Claim name. |
|
| 19 | - * |
|
| 20 | - * @var string $_name |
|
| 21 | - */ |
|
| 22 | - protected $_name; |
|
| 17 | + /** |
|
| 18 | + * Claim name. |
|
| 19 | + * |
|
| 20 | + * @var string $_name |
|
| 21 | + */ |
|
| 22 | + protected $_name; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Claim value. |
|
| 26 | - * |
|
| 27 | - * @var mixed $_value |
|
| 28 | - */ |
|
| 29 | - protected $_value; |
|
| 24 | + /** |
|
| 25 | + * Claim value. |
|
| 26 | + * |
|
| 27 | + * @var mixed $_value |
|
| 28 | + */ |
|
| 29 | + protected $_value; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Claim validator. |
|
| 33 | - * |
|
| 34 | - * @var Validator|null $_validator |
|
| 35 | - */ |
|
| 36 | - protected $_validator; |
|
| 31 | + /** |
|
| 32 | + * Claim validator. |
|
| 33 | + * |
|
| 34 | + * @var Validator|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 Validator|null $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 Validator|null $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 | - * @return Claim |
|
| 61 | - */ |
|
| 62 | - public static function fromNameAndValue(string $name, $value) |
|
| 63 | - { |
|
| 64 | - if (array_key_exists($name, RegisteredClaim::MAP_NAME_TO_CLASS)) { |
|
| 65 | - $cls = RegisteredClaim::MAP_NAME_TO_CLASS[$name]; |
|
| 66 | - return $cls::fromJSONValue($value); |
|
| 67 | - } |
|
| 68 | - return new self($name, $value); |
|
| 69 | - } |
|
| 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 | + * @return Claim |
|
| 61 | + */ |
|
| 62 | + public static function fromNameAndValue(string $name, $value) |
|
| 63 | + { |
|
| 64 | + if (array_key_exists($name, RegisteredClaim::MAP_NAME_TO_CLASS)) { |
|
| 65 | + $cls = RegisteredClaim::MAP_NAME_TO_CLASS[$name]; |
|
| 66 | + return $cls::fromJSONValue($value); |
|
| 67 | + } |
|
| 68 | + return new self($name, $value); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get the claim name. |
|
| 73 | - * |
|
| 74 | - * @return string |
|
| 75 | - */ |
|
| 76 | - public function name(): string |
|
| 77 | - { |
|
| 78 | - return $this->_name; |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Get the claim name. |
|
| 73 | + * |
|
| 74 | + * @return string |
|
| 75 | + */ |
|
| 76 | + public function name(): string |
|
| 77 | + { |
|
| 78 | + return $this->_name; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Get the claim value. |
|
| 83 | - * |
|
| 84 | - * @return mixed |
|
| 85 | - */ |
|
| 86 | - public function value() |
|
| 87 | - { |
|
| 88 | - return $this->_value; |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Get the claim value. |
|
| 83 | + * |
|
| 84 | + * @return mixed |
|
| 85 | + */ |
|
| 86 | + public function value() |
|
| 87 | + { |
|
| 88 | + return $this->_value; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Validate the claim against a given constraint. |
|
| 93 | - * |
|
| 94 | - * @param mixed $constraint Constraint value |
|
| 95 | - * @return bool True if the claim is valid |
|
| 96 | - */ |
|
| 97 | - public function validate($constraint): bool |
|
| 98 | - { |
|
| 99 | - // if claim has no validator, consider validation failed |
|
| 100 | - if (!isset($this->_validator)) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - return $this->_validator->validate($this->_value, $constraint); |
|
| 104 | - } |
|
| 91 | + /** |
|
| 92 | + * Validate the claim against a given constraint. |
|
| 93 | + * |
|
| 94 | + * @param mixed $constraint Constraint value |
|
| 95 | + * @return bool True if the claim is valid |
|
| 96 | + */ |
|
| 97 | + public function validate($constraint): bool |
|
| 98 | + { |
|
| 99 | + // if claim has no validator, consider validation failed |
|
| 100 | + if (!isset($this->_validator)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + return $this->_validator->validate($this->_value, $constraint); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Validate the claim in a given context. |
|
| 108 | - * |
|
| 109 | - * @param ValidationContext $ctx |
|
| 110 | - * @return bool True if claim is valid |
|
| 111 | - */ |
|
| 112 | - public function validateWithContext(ValidationContext $ctx): bool |
|
| 113 | - { |
|
| 114 | - // if validator has no constraint for the claim |
|
| 115 | - if (!$ctx->hasConstraint($this->_name)) { |
|
| 116 | - return true; |
|
| 117 | - } |
|
| 118 | - $constraint = $ctx->constraint($this->_name); |
|
| 119 | - // if validation context has an explicitly |
|
| 120 | - // defined validator for the claim |
|
| 121 | - if ($ctx->hasValidator($this->_name)) { |
|
| 122 | - return $ctx->validator($this->_name)->validate($this->_value, |
|
| 123 | - $constraint); |
|
| 124 | - } |
|
| 125 | - // validate using claim's default validator |
|
| 126 | - return $this->validate($ctx->constraint($this->_name)); |
|
| 127 | - } |
|
| 106 | + /** |
|
| 107 | + * Validate the claim in a given context. |
|
| 108 | + * |
|
| 109 | + * @param ValidationContext $ctx |
|
| 110 | + * @return bool True if claim is valid |
|
| 111 | + */ |
|
| 112 | + public function validateWithContext(ValidationContext $ctx): bool |
|
| 113 | + { |
|
| 114 | + // if validator has no constraint for the claim |
|
| 115 | + if (!$ctx->hasConstraint($this->_name)) { |
|
| 116 | + return true; |
|
| 117 | + } |
|
| 118 | + $constraint = $ctx->constraint($this->_name); |
|
| 119 | + // if validation context has an explicitly |
|
| 120 | + // defined validator for the claim |
|
| 121 | + if ($ctx->hasValidator($this->_name)) { |
|
| 122 | + return $ctx->validator($this->_name)->validate($this->_value, |
|
| 123 | + $constraint); |
|
| 124 | + } |
|
| 125 | + // validate using claim's default validator |
|
| 126 | + return $this->validate($ctx->constraint($this->_name)); |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -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 |
|
| 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 |
|
| 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 | } |
@@ -13,14 +13,14 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class IssuerClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $issuer |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $issuer) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_ISSUER, $issuer, |
|
| 24 | - new EqualsValidator()); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $issuer |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $issuer) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_ISSUER, $issuer, |
|
| 24 | + new EqualsValidator()); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -13,14 +13,14 @@ |
||
| 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, |
|
| 24 | - new EqualsValidator()); |
|
| 25 | - } |
|
| 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, |
|
| 24 | + new EqualsValidator()); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class SubjectClaim extends RegisteredClaim |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param string $subject Subject |
|
| 20 | - */ |
|
| 21 | - public function __construct(string $subject) |
|
| 22 | - { |
|
| 23 | - parent::__construct(self::NAME_SUBJECT, $subject, new EqualsValidator()); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param string $subject Subject |
|
| 20 | + */ |
|
| 21 | + public function __construct(string $subject) |
|
| 22 | + { |
|
| 23 | + parent::__construct(self::NAME_SUBJECT, $subject, new EqualsValidator()); |
|
| 24 | + } |
|
| 25 | 25 | } |