Skip to content

Commit

Permalink
Dont parse input when it`s empty
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed Jan 20, 2016
1 parent 2878a3a commit 55b05cd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Phramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,10 @@ public static function getTranslated(

/**
* Execute the API
* @throws Phramework\Exceptions\PermissionException
* @throws Phramework\Exceptions\NotFoundException
* @throws Phramework\Exceptions\IncorrectParametersException
* @throws Phramework\Exceptions\RequestException
* @throws \Phramework\Exceptions\PermissionException
* @throws \Phramework\Exceptions\NotFoundException
* @throws \Phramework\Exceptions\IncorrectParametersException
* @throws \Phramework\Exceptions\RequestException
* @todo change default timezone
* @todo change default language
* @todo initialize database if set
Expand Down Expand Up @@ -337,7 +337,7 @@ public function invoke()

//Parse request body
//@Todo add allowed content-types
if (in_array(
if (!empty($input) && in_array(
$method,
[
self::METHOD_POST,
Expand Down Expand Up @@ -369,16 +369,16 @@ public function invoke()
//note if input length is >0 and decode returns null then its bad data
//json_last_error()

$input = json_decode($input);
$inputObject = json_decode($input);

if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Phramework\Exceptions\RequestException(
'JSON parse error - ' . json_last_error_msg()
'JSON parse error: ' . json_last_error_msg()
);
}

if ($input && !empty($input)) {
$params = (object)array_merge((array)$params, (array)$input);
if ($inputObject && !empty($inputObject)) {
$params = (object)array_merge((array)$params, (array)$inputObject);
}
}
}
Expand Down

0 comments on commit 55b05cd

Please sign in to comment.