[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 declare(strict_types=1); 4 5 /* 6 * The MIT License (MIT) 7 * 8 * Copyright (c) 2014-2020 Spomky-Labs 9 * 10 * This software may be modified and distributed under the terms 11 * of the MIT license. See the LICENSE file for details. 12 */ 13 14 namespace Jose\Component\Signature; 15 16 use function array_key_exists; 17 use InvalidArgumentException; 18 19 class Signature 20 { 21 /** 22 * @var null|string 23 */ 24 private $encodedProtectedHeader; 25 26 /** 27 * @var array 28 */ 29 private $protectedHeader; 30 31 /** 32 * @var array 33 */ 34 private $header; 35 36 /** 37 * @var string 38 */ 39 private $signature; 40 41 public function __construct(string $signature, array $protectedHeader, ?string $encodedProtectedHeader, array $header) 42 { 43 $this->protectedHeader = null === $encodedProtectedHeader ? [] : $protectedHeader; 44 $this->encodedProtectedHeader = $encodedProtectedHeader; 45 $this->signature = $signature; 46 $this->header = $header; 47 } 48 49 /** 50 * The protected header associated with the signature. 51 */ 52 public function getProtectedHeader(): array 53 { 54 return $this->protectedHeader; 55 } 56 57 /** 58 * The unprotected header associated with the signature. 59 */ 60 public function getHeader(): array 61 { 62 return $this->header; 63 } 64 65 /** 66 * The protected header associated with the signature. 67 */ 68 public function getEncodedProtectedHeader(): ?string 69 { 70 return $this->encodedProtectedHeader; 71 } 72 73 /** 74 * Returns the value of the protected header of the specified key. 75 * 76 * @param string $key The key 77 * 78 * @throws InvalidArgumentException if the header parameter does not exist 79 * 80 * @return null|mixed Header value 81 */ 82 public function getProtectedHeaderParameter(string $key) 83 { 84 if ($this->hasProtectedHeaderParameter($key)) { 85 return $this->getProtectedHeader()[$key]; 86 } 87 88 throw new InvalidArgumentException(sprintf('The protected header "%s" does not exist', $key)); 89 } 90 91 /** 92 * Returns true if the protected header has the given parameter. 93 * 94 * @param string $key The key 95 */ 96 public function hasProtectedHeaderParameter(string $key): bool 97 { 98 return array_key_exists($key, $this->getProtectedHeader()); 99 } 100 101 /** 102 * Returns the value of the unprotected header of the specified key. 103 * 104 * @param string $key The key 105 * 106 * @return null|mixed Header value 107 */ 108 public function getHeaderParameter(string $key) 109 { 110 if ($this->hasHeaderParameter($key)) { 111 return $this->header[$key]; 112 } 113 114 throw new InvalidArgumentException(sprintf('The header "%s" does not exist', $key)); 115 } 116 117 /** 118 * Returns true if the unprotected header has the given parameter. 119 * 120 * @param string $key The key 121 */ 122 public function hasHeaderParameter(string $key): bool 123 { 124 return array_key_exists($key, $this->header); 125 } 126 127 /** 128 * Returns the value of the signature. 129 */ 130 public function getSignature(): string 131 { 132 return $this->signature; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |