PluginProbe
Depicter — Popup & Slider Builder / 1.3.2
Depicter — Popup & Slider Builder v1.3.2
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / averta / core / src / Utility / JSON.php

JSON.php in Depicter — Popup & Slider Builder 1.3.2, at vendor/averta/core/src/Utility/JSON.php

50 lines 924 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Averta\Core\Utility;
3
4
5 class JSON
6 {
7 /**
8 * Detect is JSON
9 *
10 * @param $args
11 *
12 * @return bool
13 */
14 public static function isJson(...$args)
15 {
16 if(is_array($args[0]) || is_object($args[0])) {
17 return false;
18 }
19
20 if (trim($args[0]) === '') {
21 return false;
22 }
23
24 json_decode(...$args);
25 return (json_last_error() == JSON_ERROR_NONE);
26 }
27
28 /**
29 * Remove extra white-spaces and tabs from json string
30 *
31 * @param string $json
32 *
33 * @return string
34 */
35 public static function normalize( $json )
36 {
37 if( ! is_string( $json ) ) {
38 return $json;
39 }
40
41 if (trim( $json ) === '') {
42 return '';
43 }
44
45 $decoded = json_decode( $json );
46 return (json_last_error() == JSON_ERROR_NONE) ? json_encode( $decoded ) : $json;
47 }
48
49 }
50