forked from php-curl-class/php-curl-class
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoder.php
More file actions
53 lines (48 loc) · 1.16 KB
/
Decoder.php
File metadata and controls
53 lines (48 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Curl;
class Decoder
{
/**
* Decode JSON
*
* @access public
* @param $json
* @param $assoc
* @param $depth
* @param $options
*/
public static function decodeJson()
{
$args = func_get_args();
// Call json_decode() without the $options parameter in PHP
// versions less than 5.4.0 as the $options parameter was added in
// PHP version 5.4.0.
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
$args = array_slice($args, 0, 3);
}
$response = call_user_func_array('json_decode', $args);
if ($response === null) {
$response = $args['0'];
}
return $response;
}
/**
* Decode XML
*
* @access public
* @param $data
* @param $class_name
* @param $options
* @param $ns
* @param $is_prefix
*/
public static function decodeXml()
{
$args = func_get_args();
$response = @call_user_func_array('simplexml_load_string', $args);
if ($response === false) {
$response = $args['0'];
}
return $response;
}
}