mirror of https://github.com/MISP/MISP
new: [API] JSON export library updated to support both attribute and event level conversions.
- relies on the old JSON library for event level conversionspull/3626/head
parent
d335196a34
commit
ba5bafd13f
|
@ -2,6 +2,8 @@
|
|||
|
||||
class JsonExport
|
||||
{
|
||||
private $__converter = false;
|
||||
|
||||
public function handler($data, $options = array())
|
||||
{
|
||||
if ($options['scope'] === 'Attribute') {
|
||||
|
@ -11,6 +13,14 @@ class JsonExport
|
|||
}
|
||||
}
|
||||
|
||||
private function __eventHandler($event, $options = array()) {
|
||||
if ($this->__converter === false) {
|
||||
App::uses('JSONConverterTool', 'Tools');
|
||||
$this->__converter = new JSONConverterTool();
|
||||
}
|
||||
return json_encode($this->__converter->convert($event, false, true));
|
||||
}
|
||||
|
||||
private function __attributeHandler($attribute, $options = array())
|
||||
{
|
||||
$attribute = array_merge($attribute['Attribute'], $attribute);
|
||||
|
@ -32,12 +42,21 @@ class JsonExport
|
|||
|
||||
public function header($options = array())
|
||||
{
|
||||
return '{"response": {"Attribute": [';
|
||||
if ($options['scope'] === 'Attribute') {
|
||||
return '{"response": {"Attribute": [';
|
||||
} else {
|
||||
return '{"response": [';
|
||||
}
|
||||
}
|
||||
|
||||
public function footer()
|
||||
public function footer($options = array())
|
||||
{
|
||||
return ']}}' . PHP_EOL;
|
||||
if ($options['scope'] === 'Attribute') {
|
||||
return ']}}' . PHP_EOL;
|
||||
} else {
|
||||
return ']}' . PHP_EOL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function separator()
|
||||
|
|
Loading…
Reference in New Issue