21 JSON_ERROR_NONE =>
'JSON_ERROR_NONE - No errors',
22 JSON_ERROR_DEPTH =>
'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
23 JSON_ERROR_STATE_MISMATCH =>
'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
24 JSON_ERROR_CTRL_CHAR =>
'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
25 JSON_ERROR_SYNTAX =>
'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
26 JSON_ERROR_UTF8 =>
'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
29 public function load($config, array $options = array())
32 $this->loadedFiles = array();
34 if (is_string($config)) {
36 } elseif (!is_array($config)) {
42 return $this->
build($config, $options);
53 public function addAlias($filename, $alias)
55 $this->aliases[$filename] = $alias;
69 unset($this->aliases[$alias]);
82 protected abstract function build($config, array $options);
93 protected function loadFile($filename)
95 if (isset($this->aliases[$filename])) {
96 $filename = $this->aliases[$filename];
99 switch (pathinfo($filename, PATHINFO_EXTENSION)) {
102 $level = error_reporting(0);
103 $json = file_get_contents($filename);
104 error_reporting($level);
106 if ($json ===
false) {
107 $err = error_get_last();
111 $config = json_decode($json,
true);
113 if ($error = json_last_error()) {
114 $message = isset(self::$jsonErrors[$error]) ? self::$jsonErrors[$error] :
'Unknown error';
115 throw new RuntimeException(
"Error loading JSON data from {$filename}: ({$error}) - {$message}");
119 if (!is_readable($filename)) {
122 $config = require $filename;
123 if (!is_array($config)) {
132 $this->loadedFiles[$filename] =
true;
150 if (!empty($config[
'includes'])) {
151 foreach ($config[
'includes'] as &$path) {
153 if ($path[0] != DIRECTORY_SEPARATOR && !isset($this->aliases[$path]) && $basePath) {
154 $path =
"{$basePath}/{$path}";
157 if (!isset($this->loadedFiles[$path])) {
158 $this->loadedFiles[$path] =
true;
173 protected function mergeData(array $a, array $b)
175 return array_merge_recursive($a, $b);