RobDWaller / ReallySimpleJWT
1
<?php
2

3
declare(strict_types=1);
4

5
namespace ReallySimpleJWT\Helper;
6

7
/**
8
 * A helper trait to encode and decode json.
9
 */
10
trait JsonEncoder
11
{
12
    /**
13
     * Consumes an associative array of data and returns a json string. Will
14
     * return the string 'false' if it fails to encode.
15
     *
16
     * @param mixed[] $jsonArray
17
     */
18 16
    public function jsonEncode(array $jsonArray): string
19
    {
20 16
        return (string) json_encode($jsonArray);
21
    }
22

23
    /**
24
     * Consumes a json string and decodes it, will always return an
25
     * associative array.
26
     *
27
     * @return mixed[]
28
     */
29 16
    public function jsonDecode(string $json): array
30
    {
31 16
        return (array) json_decode($json, true);
32
    }
33
}

Read our documentation on viewing source code .

Loading