Remove JSON request parsing from Server

This commit is contained in:
Thomas Tanghus 2013-09-30 16:24:47 +02:00
parent 7cd8088845
commit 0f13ffb773
2 changed files with 1 additions and 13 deletions

View File

@ -42,14 +42,12 @@ class Request implements \ArrayAccess, \Countable, IRequest {
'env', 'env',
'cookies', 'cookies',
'urlParams', 'urlParams',
'params',
'parameters', 'parameters',
'method' 'method'
); );
/** /**
* @param array $vars An associative array with the following optional values: * @param array $vars An associative array with the following optional values:
* @param array 'params' the parsed json array
* @param array 'urlParams' the parameters which were matched from the URL * @param array 'urlParams' the parameters which were matched from the URL
* @param array 'get' the $_GET array * @param array 'get' the $_GET array
* @param array|string 'post' the $_POST array or JSON string * @param array|string 'post' the $_POST array or JSON string
@ -74,11 +72,10 @@ class Request implements \ArrayAccess, \Countable, IRequest {
if (isset($this->items['post']) if (isset($this->items['post'])
&& strpos($this->getHeader('Content-Type'), 'application/json') !== false && strpos($this->getHeader('Content-Type'), 'application/json') !== false
&& is_string($this->items['post'])) { && is_string($this->items['post'])) {
$this->items['post'] = json_decode($this->items['post'], true); $this->items['params'] = $this->items['post'] = json_decode($this->items['post'], true);
} }
$this->items['parameters'] = array_merge( $this->items['parameters'] = array_merge(
$this->items['params'],
$this->items['get'], $this->items['get'],
$this->items['post'], $this->items['post'],
$this->items['urlParams'] $this->items['urlParams']

View File

@ -22,14 +22,6 @@ class Server extends SimpleContainer implements IServerContainer {
return new ContactsManager(); return new ContactsManager();
}); });
$this->registerService('Request', function($c) { $this->registerService('Request', function($c) {
$params = array();
// we json decode the body only in case of content type json
if (isset($_SERVER['CONTENT_TYPE']) && stripos($_SERVER['CONTENT_TYPE'],'json') !== false ) {
$params = json_decode(file_get_contents('php://input'), true);
$params = is_array($params) ? $params: array();
}
return new Request( return new Request(
array( array(
'get' => $_GET, 'get' => $_GET,
@ -41,7 +33,6 @@ class Server extends SimpleContainer implements IServerContainer {
'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
? $_SERVER['REQUEST_METHOD'] ? $_SERVER['REQUEST_METHOD']
: null, : null,
'params' => $params,
'urlParams' => $c['urlParams'] 'urlParams' => $c['urlParams']
) )
); );