|
1
|
|
|
<?php |
|
2
|
|
|
namespace SEOstats\Helper; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* URL-String Helper Class |
|
6
|
|
|
* |
|
7
|
|
|
* @package SEOstats |
|
8
|
|
|
* @author Stephan Schmitz <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2010 - present Stephan Schmitz |
|
10
|
|
|
* @license http://eyecatchup.mit-license.org/ MIT License |
|
11
|
|
|
* @updated 2013/02/03 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
class Json |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Decodes a JSON string into appropriate variable. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $str JSON-formatted string |
|
20
|
|
|
* @param boolean $accos When true, returned objects will be converted into associative arrays. |
|
|
|
|
|
|
21
|
|
|
* @return mixed number, boolean, string, array, or object corresponding to given JSON input string. |
|
22
|
|
|
* Note that decode() always returns strings in ASCII or UTF-8 format! |
|
23
|
|
|
*/ |
|
24
|
34 |
|
public static function decode($str, $assoc = false) |
|
25
|
|
|
{ |
|
26
|
34 |
|
if (!function_exists('json_decode')) { |
|
27
|
|
|
$j = self::getJsonService(); |
|
28
|
|
|
return $j->decode($str); |
|
29
|
|
|
} |
|
30
|
|
|
else { |
|
31
|
34 |
|
return $assoc ? json_decode($str, true) : json_decode($str); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Encodes an arbitrary variable into JSON format. |
|
37
|
|
|
* |
|
38
|
|
|
* @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
39
|
|
|
* if var is a string, note that encode() always expects it |
|
40
|
|
|
* to be in ASCII or UTF-8 format! |
|
41
|
|
|
* @return mixed JSON string representation of input var or an error if a problem occurs |
|
42
|
|
|
*/ |
|
43
|
2 |
|
public static function encode($var) |
|
44
|
|
|
{ |
|
45
|
2 |
|
if (!function_exists('json_encode')) { |
|
46
|
|
|
$j = self::getJsonService(); |
|
47
|
|
|
return $j->encode($var); |
|
48
|
|
|
} |
|
49
|
|
|
else { |
|
50
|
2 |
|
return json_encode($var); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Return a new object of Services_JSON class. |
|
56
|
|
|
* Used if native PHP JSON extension is not available. |
|
57
|
|
|
*/ |
|
58
|
|
|
private static function getJsonService() |
|
59
|
|
|
{ |
|
60
|
|
|
return new \Services_JSON(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.