[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS 4 * 5 * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause 6 */ 7 8 namespace Lcobucci\JWT\Signer; 9 10 use Exception; 11 use InvalidArgumentException; 12 use Lcobucci\JWT\Signer\Key\FileCouldNotBeRead; 13 use SplFileObject; 14 15 use function strpos; 16 use function substr; 17 18 /** 19 * @author Luís Otávio Cobucci Oblonczyk <[email protected]> 20 * @since 3.0.4 21 */ 22 class Key 23 { 24 /** 25 * @var string 26 */ 27 protected $content; 28 29 /** 30 * @var string 31 */ 32 private $passphrase; 33 34 /** 35 * @param string $content 36 * @param string $passphrase 37 */ 38 public function __construct($content, $passphrase = '') 39 { 40 $this->setContent($content); 41 $this->passphrase = $passphrase; 42 } 43 44 /** 45 * @param string $content 46 * 47 * @throws InvalidArgumentException 48 */ 49 private function setContent($content) 50 { 51 if (strpos($content, 'file://') === 0) { 52 $content = $this->readFile($content); 53 } 54 55 $this->content = $content; 56 } 57 58 /** 59 * @param string $content 60 * 61 * @return string 62 * 63 * @throws InvalidArgumentException 64 */ 65 private function readFile($content) 66 { 67 $path = substr($content, 7); 68 69 try { 70 $file = new SplFileObject($path); 71 } catch (Exception $exception) { 72 throw FileCouldNotBeRead::onPath($path, $exception); 73 } 74 75 $content = ''; 76 77 while (! $file->eof()) { 78 $content .= $file->fgets(); 79 } 80 81 return $content; 82 } 83 84 /** @return string */ 85 public function contents() 86 { 87 return $this->content; 88 } 89 90 /** @return string */ 91 public function passphrase() 92 { 93 return $this->passphrase; 94 } 95 96 /** 97 * @deprecated This method is no longer part of the public interface 98 * @see Key::contents() 99 * 100 * @return string 101 */ 102 public function getContent() 103 { 104 return $this->content; 105 } 106 107 /** 108 * @deprecated This method is no longer part of the public interface 109 * @see Key::passphrase() 110 * 111 * @return string 112 */ 113 public function getPassphrase() 114 { 115 return $this->passphrase; 116 } 117 }
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 |