| @@ 28-30 (lines=3) @@ | ||
| 25 | */ |
|
| 26 | public static function encode(Context $context, $payload, $key, $jweAlgorithm, $jweEncryption, array $extraHeaders = []) |
|
| 27 | { |
|
| 28 | if (empty($payload) || (is_string($payload) && trim($payload) == '')) { |
|
| 29 | throw new JoseJwtException('Payload can not be empty'); |
|
| 30 | } |
|
| 31 | $algorithm = $context->jweAlgorithms()->get($jweAlgorithm); |
|
| 32 | if (null === $algorithm) { |
|
| 33 | throw new JoseJwtException(sprintf('Invalid or unsupported algorithm "%s"', $jweAlgorithm)); |
|
| @@ 103-109 (lines=7) @@ | ||
| 100 | { |
|
| 101 | if (is_array($payload)) { |
|
| 102 | return json_encode($payload, JSON_UNESCAPED_SLASHES); |
|
| 103 | } elseif (is_string($payload)) { |
|
| 104 | if (trim($payload) !== '') { |
|
| 105 | return $payload; |
|
| 106 | } else { |
|
| 107 | throw new JoseJwtException('Payload can not be empty'); |
|
| 108 | } |
|
| 109 | } elseif (is_object($payload) && $payload instanceof \JsonSerializable) { |
|
| 110 | return json_encode($payload, JSON_UNESCAPED_SLASHES); |
|
| 111 | } elseif (is_object($payload) && $mapper) { |
|
| 112 | return $mapper->getJsonString($payload); |
|