@@ -13,116 +13,116 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class CurveParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * P-256 Curve. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - const CURVE_P256 = "P-256"; |
|
| 18 | + /** |
|
| 19 | + * P-256 Curve. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + const CURVE_P256 = "P-256"; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * P-384 Curve. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - const CURVE_P384 = "P-384"; |
|
| 25 | + /** |
|
| 26 | + * P-384 Curve. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + const CURVE_P384 = "P-384"; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * P-521 Curve. |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - const CURVE_P521 = "P-521"; |
|
| 32 | + /** |
|
| 33 | + * P-521 Curve. |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + const CURVE_P521 = "P-521"; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Mapping from curve OID to curve name. |
|
| 41 | - * |
|
| 42 | - * @internal |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - const MAP_OID_TO_CURVE = array( |
|
| 47 | - /* @formatter:off */ |
|
| 48 | - "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
| 49 | - "1.3.132.0.34" => self::CURVE_P384, |
|
| 50 | - "1.3.132.0.35" => self::CURVE_P521 |
|
| 51 | - /* @formatter:on */ |
|
| 52 | - ); |
|
| 39 | + /** |
|
| 40 | + * Mapping from curve OID to curve name. |
|
| 41 | + * |
|
| 42 | + * @internal |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + const MAP_OID_TO_CURVE = array( |
|
| 47 | + /* @formatter:off */ |
|
| 48 | + "1.2.840.10045.3.1.7" => self::CURVE_P256, |
|
| 49 | + "1.3.132.0.34" => self::CURVE_P384, |
|
| 50 | + "1.3.132.0.35" => self::CURVE_P521 |
|
| 51 | + /* @formatter:on */ |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Mapping from curve name to bit size. |
|
| 56 | - * |
|
| 57 | - * @internal |
|
| 58 | - * |
|
| 59 | - * @var array |
|
| 60 | - */ |
|
| 61 | - const MAP_CURVE_TO_SIZE = array( |
|
| 62 | - /* @formatter:off */ |
|
| 63 | - self::CURVE_P256 => 256, |
|
| 64 | - self::CURVE_P384 => 384, |
|
| 65 | - self::CURVE_P521 => 521 |
|
| 66 | - /* @formatter:on */ |
|
| 67 | - ); |
|
| 54 | + /** |
|
| 55 | + * Mapping from curve name to bit size. |
|
| 56 | + * |
|
| 57 | + * @internal |
|
| 58 | + * |
|
| 59 | + * @var array |
|
| 60 | + */ |
|
| 61 | + const MAP_CURVE_TO_SIZE = array( |
|
| 62 | + /* @formatter:off */ |
|
| 63 | + self::CURVE_P256 => 256, |
|
| 64 | + self::CURVE_P384 => 384, |
|
| 65 | + self::CURVE_P521 => 521 |
|
| 66 | + /* @formatter:on */ |
|
| 67 | + ); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Constructor. |
|
| 71 | - * |
|
| 72 | - * @param string $curve Curve name |
|
| 73 | - */ |
|
| 74 | - public function __construct(string $curve) |
|
| 75 | - { |
|
| 76 | - parent::__construct(self::PARAM_CURVE, $curve); |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * Constructor. |
|
| 71 | + * |
|
| 72 | + * @param string $curve Curve name |
|
| 73 | + */ |
|
| 74 | + public function __construct(string $curve) |
|
| 75 | + { |
|
| 76 | + parent::__construct(self::PARAM_CURVE, $curve); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Initialize from curve OID. |
|
| 81 | - * |
|
| 82 | - * @param string $oid Object identifier in dotted format |
|
| 83 | - * @throws \UnexpectedValueException If the curve is not supported |
|
| 84 | - * @return self |
|
| 85 | - */ |
|
| 86 | - public static function fromOID(string $oid): self |
|
| 87 | - { |
|
| 88 | - if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
| 89 | - throw new \UnexpectedValueException("OID $oid not supported."); |
|
| 90 | - } |
|
| 91 | - $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
| 92 | - return new self($curve); |
|
| 93 | - } |
|
| 79 | + /** |
|
| 80 | + * Initialize from curve OID. |
|
| 81 | + * |
|
| 82 | + * @param string $oid Object identifier in dotted format |
|
| 83 | + * @throws \UnexpectedValueException If the curve is not supported |
|
| 84 | + * @return self |
|
| 85 | + */ |
|
| 86 | + public static function fromOID(string $oid): self |
|
| 87 | + { |
|
| 88 | + if (!array_key_exists($oid, self::MAP_OID_TO_CURVE)) { |
|
| 89 | + throw new \UnexpectedValueException("OID $oid not supported."); |
|
| 90 | + } |
|
| 91 | + $curve = self::MAP_OID_TO_CURVE[$oid]; |
|
| 92 | + return new self($curve); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get key size in bits for the curve. |
|
| 97 | - * |
|
| 98 | - * @throws \UnexpectedValueException |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - public function keySizeBits(): int |
|
| 102 | - { |
|
| 103 | - if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
| 104 | - throw new \UnexpectedValueException( |
|
| 105 | - "Curve " . $this->_value . " not supported."); |
|
| 106 | - } |
|
| 107 | - return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
| 108 | - } |
|
| 95 | + /** |
|
| 96 | + * Get key size in bits for the curve. |
|
| 97 | + * |
|
| 98 | + * @throws \UnexpectedValueException |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + public function keySizeBits(): int |
|
| 102 | + { |
|
| 103 | + if (!array_key_exists($this->_value, self::MAP_CURVE_TO_SIZE)) { |
|
| 104 | + throw new \UnexpectedValueException( |
|
| 105 | + "Curve " . $this->_value . " not supported."); |
|
| 106 | + } |
|
| 107 | + return self::MAP_CURVE_TO_SIZE[$this->_value]; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Get the curve OID by curve name. |
|
| 112 | - * |
|
| 113 | - * @param string $name Curve parameter name |
|
| 114 | - * @throws \UnexpectedValueException If the curve is not supported |
|
| 115 | - * @return string OID in dotted format |
|
| 116 | - */ |
|
| 117 | - public static function nameToOID(string $name): string |
|
| 118 | - { |
|
| 119 | - static $reverseMap; |
|
| 120 | - if (!isset($reverseMap)) { |
|
| 121 | - $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
| 122 | - } |
|
| 123 | - if (!isset($reverseMap[$name])) { |
|
| 124 | - throw new \UnexpectedValueException("Curve $name not supported."); |
|
| 125 | - } |
|
| 126 | - return $reverseMap[$name]; |
|
| 127 | - } |
|
| 110 | + /** |
|
| 111 | + * Get the curve OID by curve name. |
|
| 112 | + * |
|
| 113 | + * @param string $name Curve parameter name |
|
| 114 | + * @throws \UnexpectedValueException If the curve is not supported |
|
| 115 | + * @return string OID in dotted format |
|
| 116 | + */ |
|
| 117 | + public static function nameToOID(string $name): string |
|
| 118 | + { |
|
| 119 | + static $reverseMap; |
|
| 120 | + if (!isset($reverseMap)) { |
|
| 121 | + $reverseMap = array_flip(self::MAP_OID_TO_CURVE); |
|
| 122 | + } |
|
| 123 | + if (!isset($reverseMap[$name])) { |
|
| 124 | + throw new \UnexpectedValueException("Curve $name not supported."); |
|
| 125 | + } |
|
| 126 | + return $reverseMap[$name]; |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ExponentParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64UIntValue; |
|
| 16 | + use Base64UIntValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $e Exponent in base64urlUInt encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $e) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($e); |
|
| 26 | - parent::__construct(self::PARAM_EXPONENT, $e); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $e Exponent in base64urlUInt encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $e) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($e); |
|
| 26 | + parent::__construct(self::PARAM_EXPONENT, $e); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,24 +13,24 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class KeyOperationsParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use ArrayParameterValue; |
|
| 16 | + use ArrayParameterValue; |
|
| 17 | 17 | |
| 18 | - const OP_SIGN = "sign"; |
|
| 19 | - const OP_VERIFY = "verify"; |
|
| 20 | - const OP_ENCRYPT = "encrypt"; |
|
| 21 | - const OP_DECRYPT = "decrypt"; |
|
| 22 | - const OP_WRAP_KEY = "wrapKey"; |
|
| 23 | - const OP_UNWRAP_KEY = "unwrapKey"; |
|
| 24 | - const OP_DERIVE_KEY = "deriveKey"; |
|
| 25 | - const OP_DERIVE_BITS = "deriveBits"; |
|
| 18 | + const OP_SIGN = "sign"; |
|
| 19 | + const OP_VERIFY = "verify"; |
|
| 20 | + const OP_ENCRYPT = "encrypt"; |
|
| 21 | + const OP_DECRYPT = "decrypt"; |
|
| 22 | + const OP_WRAP_KEY = "wrapKey"; |
|
| 23 | + const OP_UNWRAP_KEY = "unwrapKey"; |
|
| 24 | + const OP_DERIVE_KEY = "deriveKey"; |
|
| 25 | + const OP_DERIVE_BITS = "deriveBits"; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param string ...$ops Key operations |
|
| 31 | - */ |
|
| 32 | - public function __construct(string ...$ops) |
|
| 33 | - { |
|
| 34 | - parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param string ...$ops Key operations |
|
| 31 | + */ |
|
| 32 | + public function __construct(string ...$ops) |
|
| 33 | + { |
|
| 34 | + parent::__construct(self::PARAM_KEY_OPERATIONS, $ops); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -13,26 +13,26 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class ECCPrivateKeyParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use Base64URLValue; |
|
| 16 | + use Base64URLValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $key Private key in base64url encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $key) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($key); |
|
| 26 | - parent::__construct(self::PARAM_ECC_PRIVATE_KEY, $key); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $key Private key in base64url encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $key) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($key); |
|
| 26 | + parent::__construct(self::PARAM_ECC_PRIVATE_KEY, $key); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Get the EC private key in octet string representation. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function privateKeyOctets(): string |
|
| 35 | - { |
|
| 36 | - return $this->string(); |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Get the EC private key in octet string representation. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function privateKeyOctets(): string |
|
| 35 | + { |
|
| 36 | + return $this->string(); |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class X509CertificateChainParameter extends JWKParameter |
| 16 | 16 | { |
| 17 | - use ArrayParameterValue; |
|
| 17 | + use ArrayParameterValue; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Constructor. |
|
| 21 | - * |
|
| 22 | - * @param string ...$certs Base64 encoded DER certificates |
|
| 23 | - */ |
|
| 24 | - public function __construct(string ...$certs) |
|
| 25 | - { |
|
| 26 | - foreach ($certs as $cert) { |
|
| 27 | - if (!Base64::isValid($cert)) { |
|
| 28 | - throw new \UnexpectedValueException( |
|
| 29 | - "Certificate must be base64 encoded."); |
|
| 30 | - } |
|
| 31 | - } |
|
| 32 | - parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
| 33 | - } |
|
| 19 | + /** |
|
| 20 | + * Constructor. |
|
| 21 | + * |
|
| 22 | + * @param string ...$certs Base64 encoded DER certificates |
|
| 23 | + */ |
|
| 24 | + public function __construct(string ...$certs) |
|
| 25 | + { |
|
| 26 | + foreach ($certs as $cert) { |
|
| 27 | + if (!Base64::isValid($cert)) { |
|
| 28 | + throw new \UnexpectedValueException( |
|
| 29 | + "Certificate must be base64 encoded."); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | + parent::__construct(self::PARAM_X509_CERTIFICATE_CHAIN, $certs); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class YCoordinateParameter extends CoordinateParameter |
| 15 | 15 | { |
| 16 | - use Base64URLValue; |
|
| 16 | + use Base64URLValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $coord Y coordinate in base64url encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $coord) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($coord); |
|
| 26 | - parent::__construct(self::PARAM_Y_COORDINATE, $coord); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $coord Y coordinate in base64url encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $coord) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($coord); |
|
| 26 | + parent::__construct(self::PARAM_Y_COORDINATE, $coord); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -13,18 +13,18 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class PublicKeyUseParameter extends JWKParameter |
| 15 | 15 | { |
| 16 | - use StringParameterValue; |
|
| 16 | + use StringParameterValue; |
|
| 17 | 17 | |
| 18 | - const USE_SIGNATURE = "sig"; |
|
| 19 | - const USE_ENCRYPTION = "enc"; |
|
| 18 | + const USE_SIGNATURE = "sig"; |
|
| 19 | + const USE_ENCRYPTION = "enc"; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Constructor. |
|
| 23 | - * |
|
| 24 | - * @param string $use Intended use of the public key |
|
| 25 | - */ |
|
| 26 | - public function __construct(string $use) |
|
| 27 | - { |
|
| 28 | - parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * Constructor. |
|
| 23 | + * |
|
| 24 | + * @param string $use Intended use of the public key |
|
| 25 | + */ |
|
| 26 | + public function __construct(string $use) |
|
| 27 | + { |
|
| 28 | + parent::__construct(self::PARAM_PUBLIC_KEY_USE, $use); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class XCoordinateParameter extends CoordinateParameter |
| 15 | 15 | { |
| 16 | - use Base64URLValue; |
|
| 16 | + use Base64URLValue; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $coord X coordinate in base64url encoding |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $coord) |
|
| 24 | - { |
|
| 25 | - $this->_validateEncoding($coord); |
|
| 26 | - parent::__construct(self::PARAM_X_COORDINATE, $coord); |
|
| 27 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $coord X coordinate in base64url encoding |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $coord) |
|
| 24 | + { |
|
| 25 | + $this->_validateEncoding($coord); |
|
| 26 | + parent::__construct(self::PARAM_X_COORDINATE, $coord); |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -14,158 +14,158 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Claims implements \Countable, \IteratorAggregate |
| 16 | 16 | { |
| 17 | - use TypedClaims; |
|
| 17 | + use TypedClaims; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Claims. |
|
| 21 | - * |
|
| 22 | - * @var Claim[] $_claims |
|
| 23 | - */ |
|
| 24 | - protected $_claims; |
|
| 19 | + /** |
|
| 20 | + * Claims. |
|
| 21 | + * |
|
| 22 | + * @var Claim[] $_claims |
|
| 23 | + */ |
|
| 24 | + protected $_claims; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param Claim ...$claims Zero or more claims |
|
| 30 | - */ |
|
| 31 | - public function __construct(Claim ...$claims) |
|
| 32 | - { |
|
| 33 | - $this->_claims = array(); |
|
| 34 | - foreach ($claims as $claim) { |
|
| 35 | - $this->_claims[$claim->name()] = $claim; |
|
| 36 | - } |
|
| 37 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param Claim ...$claims Zero or more claims |
|
| 30 | + */ |
|
| 31 | + public function __construct(Claim ...$claims) |
|
| 32 | + { |
|
| 33 | + $this->_claims = array(); |
|
| 34 | + foreach ($claims as $claim) { |
|
| 35 | + $this->_claims[$claim->name()] = $claim; |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initialize from a JSON string. |
|
| 41 | - * |
|
| 42 | - * @param string $json JSON |
|
| 43 | - * @throws \UnexpectedValueException If JSON is malformed |
|
| 44 | - * @return self |
|
| 45 | - */ |
|
| 46 | - public static function fromJSON(string $json): self |
|
| 47 | - { |
|
| 48 | - $claims = array(); |
|
| 49 | - $fields = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
| 50 | - if (!is_array($fields)) { |
|
| 51 | - throw new \UnexpectedValueException("Invalid JSON."); |
|
| 52 | - } |
|
| 53 | - foreach ($fields as $name => $value) { |
|
| 54 | - $claims[] = Claim::fromNameAndValue($name, $value); |
|
| 55 | - } |
|
| 56 | - return new self(...$claims); |
|
| 57 | - } |
|
| 39 | + /** |
|
| 40 | + * Initialize from a JSON string. |
|
| 41 | + * |
|
| 42 | + * @param string $json JSON |
|
| 43 | + * @throws \UnexpectedValueException If JSON is malformed |
|
| 44 | + * @return self |
|
| 45 | + */ |
|
| 46 | + public static function fromJSON(string $json): self |
|
| 47 | + { |
|
| 48 | + $claims = array(); |
|
| 49 | + $fields = json_decode($json, true, 32, JSON_BIGINT_AS_STRING); |
|
| 50 | + if (!is_array($fields)) { |
|
| 51 | + throw new \UnexpectedValueException("Invalid JSON."); |
|
| 52 | + } |
|
| 53 | + foreach ($fields as $name => $value) { |
|
| 54 | + $claims[] = Claim::fromNameAndValue($name, $value); |
|
| 55 | + } |
|
| 56 | + return new self(...$claims); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get self with Claim objects added. |
|
| 61 | - * |
|
| 62 | - * @param Claim ...$claims One or more Claim objects |
|
| 63 | - * @return self |
|
| 64 | - */ |
|
| 65 | - public function withClaims(Claim ...$claims): self |
|
| 66 | - { |
|
| 67 | - $obj = clone $this; |
|
| 68 | - foreach ($claims as $claim) { |
|
| 69 | - $obj->_claims[$claim->name()] = $claim; |
|
| 70 | - } |
|
| 71 | - return $obj; |
|
| 72 | - } |
|
| 59 | + /** |
|
| 60 | + * Get self with Claim objects added. |
|
| 61 | + * |
|
| 62 | + * @param Claim ...$claims One or more Claim objects |
|
| 63 | + * @return self |
|
| 64 | + */ |
|
| 65 | + public function withClaims(Claim ...$claims): self |
|
| 66 | + { |
|
| 67 | + $obj = clone $this; |
|
| 68 | + foreach ($claims as $claim) { |
|
| 69 | + $obj->_claims[$claim->name()] = $claim; |
|
| 70 | + } |
|
| 71 | + return $obj; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Get all claims. |
|
| 76 | - * |
|
| 77 | - * @return Claim[] |
|
| 78 | - */ |
|
| 79 | - public function all(): array |
|
| 80 | - { |
|
| 81 | - return $this->_claims; |
|
| 82 | - } |
|
| 74 | + /** |
|
| 75 | + * Get all claims. |
|
| 76 | + * |
|
| 77 | + * @return Claim[] |
|
| 78 | + */ |
|
| 79 | + public function all(): array |
|
| 80 | + { |
|
| 81 | + return $this->_claims; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Check whether claim is present. |
|
| 86 | - * |
|
| 87 | - * @param string $name Claim name |
|
| 88 | - * @return true |
|
| 89 | - */ |
|
| 90 | - public function has(string $name): bool |
|
| 91 | - { |
|
| 92 | - return isset($this->_claims[$name]); |
|
| 93 | - } |
|
| 84 | + /** |
|
| 85 | + * Check whether claim is present. |
|
| 86 | + * |
|
| 87 | + * @param string $name Claim name |
|
| 88 | + * @return true |
|
| 89 | + */ |
|
| 90 | + public function has(string $name): bool |
|
| 91 | + { |
|
| 92 | + return isset($this->_claims[$name]); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get claim by name. |
|
| 97 | - * |
|
| 98 | - * @param string $name Claim name |
|
| 99 | - * @throws \LogicException If claim is not present |
|
| 100 | - * @return Claim |
|
| 101 | - */ |
|
| 102 | - public function get(string $name): Claim |
|
| 103 | - { |
|
| 104 | - if (!isset($this->_claims[$name])) { |
|
| 105 | - throw new \LogicException("Claim $name not set."); |
|
| 106 | - } |
|
| 107 | - return $this->_claims[$name]; |
|
| 108 | - } |
|
| 95 | + /** |
|
| 96 | + * Get claim by name. |
|
| 97 | + * |
|
| 98 | + * @param string $name Claim name |
|
| 99 | + * @throws \LogicException If claim is not present |
|
| 100 | + * @return Claim |
|
| 101 | + */ |
|
| 102 | + public function get(string $name): Claim |
|
| 103 | + { |
|
| 104 | + if (!isset($this->_claims[$name])) { |
|
| 105 | + throw new \LogicException("Claim $name not set."); |
|
| 106 | + } |
|
| 107 | + return $this->_claims[$name]; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Convert to a JSON. |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function toJSON(): string |
|
| 116 | - { |
|
| 117 | - $data = array(); |
|
| 118 | - foreach ($this->_claims as $claim) { |
|
| 119 | - $data[$claim->name()] = $claim->value(); |
|
| 120 | - } |
|
| 121 | - return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
| 122 | - } |
|
| 110 | + /** |
|
| 111 | + * Convert to a JSON. |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function toJSON(): string |
|
| 116 | + { |
|
| 117 | + $data = array(); |
|
| 118 | + foreach ($this->_claims as $claim) { |
|
| 119 | + $data[$claim->name()] = $claim->value(); |
|
| 120 | + } |
|
| 121 | + return json_encode((object) $data, JSON_UNESCAPED_SLASHES); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Check whether a claims set is valid in the given context. |
|
| 126 | - * |
|
| 127 | - * @param ValidationContext $ctx Validation context |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - public function isValid(ValidationContext $ctx): bool |
|
| 131 | - { |
|
| 132 | - try { |
|
| 133 | - $ctx->validate($this); |
|
| 134 | - } catch (\RuntimeException $e) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 124 | + /** |
|
| 125 | + * Check whether a claims set is valid in the given context. |
|
| 126 | + * |
|
| 127 | + * @param ValidationContext $ctx Validation context |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + public function isValid(ValidationContext $ctx): bool |
|
| 131 | + { |
|
| 132 | + try { |
|
| 133 | + $ctx->validate($this); |
|
| 134 | + } catch (\RuntimeException $e) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Get the number of claims. |
|
| 142 | - * |
|
| 143 | - * @see \Countable::count() |
|
| 144 | - * @return int |
|
| 145 | - */ |
|
| 146 | - public function count(): int |
|
| 147 | - { |
|
| 148 | - return count($this->_claims); |
|
| 149 | - } |
|
| 140 | + /** |
|
| 141 | + * Get the number of claims. |
|
| 142 | + * |
|
| 143 | + * @see \Countable::count() |
|
| 144 | + * @return int |
|
| 145 | + */ |
|
| 146 | + public function count(): int |
|
| 147 | + { |
|
| 148 | + return count($this->_claims); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get iterator for Claim objects keyed by claim name. |
|
| 153 | - * |
|
| 154 | - * @see \IteratorAggregate::getIterator() |
|
| 155 | - * @return \ArrayIterator |
|
| 156 | - */ |
|
| 157 | - public function getIterator(): \ArrayIterator |
|
| 158 | - { |
|
| 159 | - return new \ArrayIterator($this->_claims); |
|
| 160 | - } |
|
| 151 | + /** |
|
| 152 | + * Get iterator for Claim objects keyed by claim name. |
|
| 153 | + * |
|
| 154 | + * @see \IteratorAggregate::getIterator() |
|
| 155 | + * @return \ArrayIterator |
|
| 156 | + */ |
|
| 157 | + public function getIterator(): \ArrayIterator |
|
| 158 | + { |
|
| 159 | + return new \ArrayIterator($this->_claims); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Convert to string. |
|
| 164 | - * |
|
| 165 | - * @return string |
|
| 166 | - */ |
|
| 167 | - public function __toString() |
|
| 168 | - { |
|
| 169 | - return $this->toJSON(); |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * Convert to string. |
|
| 164 | + * |
|
| 165 | + * @return string |
|
| 166 | + */ |
|
| 167 | + public function __toString() |
|
| 168 | + { |
|
| 169 | + return $this->toJSON(); |
|
| 170 | + } |
|
| 171 | 171 | } |