-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
49 lines (40 loc) · 1.03 KB
/
index.php
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
<?php
namespace tangible\hjson;
use tangible\hjson;
function parse($content, $options = []) {
static $parser;
if (!$parser) {
require_once __DIR__.'/HJSONException.php';
require_once __DIR__.'/HJSONUtils.php';
require_once __DIR__.'/HJSONParser.php';
$parser = new hjson\HJSONParser();
}
$parse_options = [
'assoc' => true // Return associative array instead of object
];
if (isset($options['throw'])) {
return $parser->parse($content, $parse_options);
}
try {
return $parser->parse($content, $parse_options);
} catch (Exception $e) {
return [];
}
};
function render($content) {
static $renderer;
if (!$renderer) {
require_once __DIR__.'/HJSONException.php';
require_once __DIR__.'/HJSONUtils.php';
require_once __DIR__.'/HJSONStringifier.php';
$renderer = new hjson\HJSONStringifier();
}
if (isset($options['throw'])) {
return $renderer->stringify($content);
}
try {
return $renderer->stringify( $content );
} catch (Exception $e) {
return '';
}
};