Verified Commit 8faa163c authored by Cyril Vazquez's avatar Cyril Vazquez
Browse files

Use new Json Stream parser

parent 7decf1d6
......@@ -47,6 +47,28 @@ class json
return $params;
}
/**
* Decode a json stream
* @param resource $stream
*
* @return mixed
*/
public static function decodeStream($stream)
{
require_once __DIR__.'/JsonTokenizer.php';
require_once __DIR__.'/JsonParser.php';
$parser = new \JsonParser();
$params = $parser->parse($stream);
if (is_object($params)) {
$params = get_object_vars($params);
}
return $params;
}
/**
* Encode data into json string
* @param mixed $data
......
......@@ -133,15 +133,13 @@ class PresentationKernel
*/
protected function parseRequest()
{
$contents = stream_get_contents($this->request->body);
if (isset($this->userInputRouter)) {
if ($this->response->mode == 'http') {
$this->response->setHeader("X-Laabs-Composer", $this->userInputRouter->uri);
}
$composer = $this->userInputRouter->composer->newInstance();
$contents = stream_get_contents($this->request->body);
$this->userMessage = $this->userInputRouter->userInput->compose($composer, $contents, $this->request->query);
} else {
switch ($this->request->queryType) {
......@@ -157,15 +155,17 @@ class PresentationKernel
switch ($this->request->contentType) {
case 'url':
$contents = stream_get_contents($this->request->body);
$bodyArguments = \core\Encoding\url::decode($contents);
break;
case 'json':
default:
$bodyArguments = \core\Encoding\json::decode($contents);
//$contents = stream_get_contents($this->request->body);
$bodyArguments = \core\Encoding\json::decodeStream($this->request->body);
break;
}
$this->userMessage = array_merge($queryArguments, $bodyArguments);
}
}
......@@ -198,6 +198,8 @@ class PresentationKernel
try {
// cast message
$serviceMessage = $servicePath->getMessage($this->userMessage);
\laabs::trace(__FILE__.'::'.__LINE__);
} catch (\core\Exception $e) {
$badRequestException = new \core\Exception\BadRequestException();
......
......@@ -189,29 +189,28 @@ class ServiceKernel extends AbstractKernel
}
$bodyArguments = array();
$contents = stream_get_contents($this->request->body);
if (isset($this->inputRouter)) {
if ($this->response->mode == 'http') {
$this->response->setHeader("X-Laabs-Parser", $this->inputRouter->uri . "; type=" . $this->request->contentType);
}
$parser = $this->inputRouter->parser->newInstance();
$contents = stream_get_contents($this->request->body);
$bodyArguments = $this->inputRouter->input->parse($parser, $contents);
} else {
switch ($this->request->contentType) {
case 'php':
$bodyArguments = $contents;
$bodyArguments = stream_get_contents($this->request->body);
break;
case 'url':
$contents = stream_get_contents($this->request->body);
$bodyArguments = \core\Encoding\url::decode($contents);
break;
case 'json':
default:
$bodyArguments = \core\Encoding\json::decode($contents);
$bodyArguments = \core\Encoding\json::decodeStream($this->request->body);
break;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment