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); }
public function testGetStringFromJsonErrorCode() { $this->assertInternalType('string', ErrorCode::getStringFromJsonErrorCode('Foo')); $contents = json_decode('{ Foo: Bar }'); $this->assertInternalType('string', ErrorCode::getStringFromJsonErrorCode(json_last_error())); }