Reads JOSN based files, strips comments and converts to array
Paramètres
(string) file: Filename:
1 call to CSSCompression::getJSON()
- CSSCompression_Color::__construct dans advagg_css_compress/
css-compressor-3.x/ src/ lib/ Color.inc - Stash a reference to the controller on each instantiation and install conversion helpers
Fichier
-
advagg_css_compress/
css-compressor-3.x/ src/ CSSCompression.inc, line 372
Classe
Code
public static function getJSON($file) {
// Assume helper file if full path not given
$file = $file[0] == '/' ? $file : dirname(__FILE__) . '/helpers/' . $file;
// Strip comments
$json = preg_replace(self::$rjson['patterns'], self::$rjson['replacements'], file_get_contents($file));
// Decode json
$json = json_decode($json, true);
// Check for errors
if ($json === NULL) {
$e = '';
// JSON Errors, taken directly from http://php.net/manual/en/function.json-last-error.php
switch (json_last_error()) {
case JSON_ERROR_NONE:
$e = 'No error has occurred';
break;
case JSON_ERROR_DEPTH:
$e = 'The maximum stack depth has been exceeded';
break;
case JSON_ERROR_CTRL_CHAR:
$e = 'Control character error, possibly incorrectly encoded';
break;
case JSON_ERROR_STATE_MISMATCH:
$e = 'Invalid or malformed JSON';
break;
case JSON_ERROR_SYNTAX:
$e = 'Syntax error';
break;
case JSON_ERROR_UTF8:
$e = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$e = 'Unknown JSON Error';
break;
}
throw new CSSCompression_Exception("JSON Error in {$file}: {$e}");
}
// Good to go
return $json;
}