FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
patternlab-php-core/src/PatternLab/JSON.php at develop · pattern-lab/patternlab-php-core · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on May 13, 2026. It is now read-only.
pattern-lab
/
patternlab-php-core
Public archive
Notifications
You must be signed in to change notification settings
Fork
61
Star
42
Code
Issues
74
Pull requests
18
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
patternlab-php-core
/
src
/
PatternLab
/
JSON.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (46 loc) · 1.68 KB
Breadcrumbs
patternlab-php-core
/
src
/
PatternLab
/
JSON.php
Copy path
File metadata and controls
54 lines (46 loc) · 1.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
54
<?php
/*!
* JSON Class
*
* Copyright (c) 2014 Dave Olsen, http://dmolsen.com
* Licensed under the MIT license
*
* Handles checking for any errors that might have been encountered when loading JSON data
*
*/
namespace
PatternLab
;
use
\
PatternLab
\
Console
;
use
\
PatternLab
\
Timer
;
use
\
Seld
\
JsonLint
;
class
JSON
{
protected
static
$
errors
=
array
(
JSON_ERROR_NONE
=>
false
,
JSON_ERROR_DEPTH
=>
'
Maximum stack depth exceeded
'
,
JSON_ERROR_STATE_MISMATCH
=>
'
Underflow or the modes mismatch
'
,
JSON_ERROR_CTRL_CHAR
=>
'
Unexpected control character found
'
,
JSON_ERROR_SYNTAX
=>
'
Syntax error, malformed JSON
'
,
JSON_ERROR_UTF8
=>
'
Malformed UTF-8 characters, possibly incorrectly encoded
'
);
/**
* Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
* @param {String} the file that generated the error
*/
public
static
function
hasError
() {
$
error
=
json_last_error
();
$
errorMessage
=
array_key_exists
(
$
error
,
self
::
$
errors
) ?
self
::
$
errors
[
$
error
] :
"
Unknown error (
{
$
error
}
)
"
;
return
$
errorMessage
;
}
/**
* Returns the last error message when building a JSON file. Mimics json_last_error_msg() from PHP 5.5
* @param {String} the file that generated the error
*/
public
static
function
lastErrorMsg
(
$
file
,
$
message
,
$
data
) {
Console::
writeLine
(
PHP_EOL
.
"
<error>The JSON file,
"
.
$
file
.
"
, wasn't loaded. The error:
"
.
$
message
.
"
</error>
"
);
if
(
$
message
==
"
Syntax error, malformed JSON
"
) {
Console::
writeLine
(
""
);
$
parser
=
new
JsonLint
\
JsonParser
();
$
error
=
$
parser
->
lint
(
$
data
);
Console::
writeError
(
$
error
->
getMessage
(),
false
,
true
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL