private function parseFromJson($results) { if (!isset($results['@json']) || !isset($results['@json'][0])) { return $results; } // Restrict the depth to avoid resolving recursive assignment // that can not be handled beyond the 2:n $depth = 3; $params = json_decode($results['@json'][0], true, $depth); if ($params === null || json_last_error() !== JSON_ERROR_NONE) { $this->addError(Message::encode(array('smw-parser-invalid-json-format', ErrorCode::getStringFromJsonErrorCode(json_last_error())))); return $results; } array_walk($params, function (&$value, $key) { if ($value === '') { $value = array(); } if (!is_array($value)) { $value = array($value); } }); unset($results['@json']); return array_merge($results, $params); }
protected function doReadJsonContentsFromFileBy($languageCode, $cacheKey) { $contents = json_decode(file_get_contents($this->getFileForLanguageCode($languageCode)), true); if ($contents !== null && json_last_error() === JSON_ERROR_NONE) { $this->cache->save($cacheKey, $contents, $this->ttl); return $contents; } throw new RuntimeException(ErrorCode::getMessageFromJsonErrorCode(json_last_error())); }
public function testGetMessageFromJsonErrorCode() { $this->assertInternalType('string', ErrorCode::getMessageFromJsonErrorCode('Foo')); $contents = json_decode('{ Foo: Bar }'); $this->assertInternalType('string', ErrorCode::getMessageFromJsonErrorCode(json_last_error())); }