[ 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\Parsing; 9 10 use JsonException; 11 use Lcobucci\JWT\Encoding\CannotEncodeContent; 12 use RuntimeException; 13 14 use function json_encode; 15 use function json_last_error; 16 use function json_last_error_msg; 17 18 /** 19 * Class that encodes data according with the specs of RFC-4648 20 * 21 * @author Luís Otávio Cobucci Oblonczyk <[email protected]> 22 * @since 0.1.0 23 * 24 * @link http://tools.ietf.org/html/rfc4648#section-5 25 */ 26 class Encoder 27 { 28 /** 29 * Encodes to JSON, validating the errors 30 * 31 * @param mixed $data 32 * @return string 33 * 34 * @throws RuntimeException When something goes wrong while encoding 35 */ 36 public function jsonEncode($data) 37 { 38 if (PHP_VERSION_ID < 70300) { 39 $json = json_encode($data); 40 41 if (json_last_error() != JSON_ERROR_NONE) { 42 throw CannotEncodeContent::jsonIssues(new JsonException(json_last_error_msg())); 43 } 44 45 return $json; 46 } 47 48 try { 49 return json_encode($data, JSON_THROW_ON_ERROR); 50 } catch (JsonException $exception) { 51 throw CannotEncodeContent::jsonIssues($exception); 52 } 53 } 54 55 /** 56 * Encodes to base64url 57 * 58 * @param string $data 59 * @return string 60 */ 61 public function base64UrlEncode($data) 62 { 63 return str_replace('=', '', strtr(base64_encode($data), '+/', '-_')); 64 } 65 }
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 |