new: [API] JSON export library updated to support both attribute and event level conversions.

- relies on the old JSON library for event level conversions
pull/3626/head
iglocska 2018-09-03 17:49:03 +02:00
parent d335196a34
commit ba5bafd13f
1 changed files with 22 additions and 3 deletions

View File

@ -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()