Skip to content

Commit

Permalink
Added to JSend::check_json_errors()
Browse files Browse the repository at this point in the history
  • Loading branch information
kemo committed Mar 7, 2012
1 parent 5d3c31f commit c03f070
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions classes/Kohana/JSend.php
Expand Up @@ -29,15 +29,18 @@ class Kohana_JSend {
/**
* Checks if an error occured during the last json_encode() / json_decode() operation
*
* @return void
* @param mixed $passthrough var to return (in case exception isn't thrown)
* @return mixed $passthrough
* @throws JSend_Exception
*/
public static function check_json_errors()
public static function check_json_errors($passthrough = NULL)
{
$error = json_last_error();

if ($error !== JSON_ERROR_NONE and $message = JSend_Exception::error_message($error))
throw new JSend_Exception($message, NULL, $error);

return $passthrough;
}

/**
Expand Down Expand Up @@ -71,9 +74,7 @@ public static function decode($json, $assoc = NULL, $depth = NULL, $options = NU

$result = json_decode($json, $assoc, $depth, $options);

JSend::check_json_errors();

return $result;
return JSend::check_json_errors($result);
}

/**
Expand All @@ -96,9 +97,7 @@ public static function encode($value, $options = NULL)
// Encode the value to JSON and check for errors
$result = json_encode($value, $options);

JSend::check_json_errors();

return $result;
return JSend::check_json_errors($result);
}

/**
Expand Down

0 comments on commit c03f070

Please sign in to comment.