Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / src / Psy / Util / Json.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Util;
13
14 /**
15  * A static class to wrap JSON encoding/decoding with PsySH's default options.
16  */
17 class Json
18 {
19     /**
20      * Encode a value as JSON.
21      *
22      * @param mixed $val
23      * @param int   $opt
24      *
25      * @return string
26      */
27     public static function encode($val, $opt = 0)
28     {
29         if (version_compare(PHP_VERSION, '5.4', '>=')) {
30             $opt |= JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
31         }
32
33         return json_encode($val, $opt);
34     }
35 }