mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 18:12:15 +00:00
Bugfixes
- Fixed filtering for get-inputs in all method. - Fixed utf-8 header issue for response()->json() method (issue: #333).
This commit is contained in:
@@ -267,29 +267,21 @@ class Input
|
|||||||
*/
|
*/
|
||||||
public function all(array $filter = null)
|
public function all(array $filter = null)
|
||||||
{
|
{
|
||||||
$output = $_POST;
|
$output = $_GET;
|
||||||
|
|
||||||
if ($this->request->getMethod() === 'post') {
|
if ($this->request->getMethod() === 'post') {
|
||||||
|
|
||||||
$contents = file_get_contents('php://input');
|
$contents = file_get_contents('php://input');
|
||||||
|
|
||||||
if (strpos(trim($contents), '{') === 0) {
|
if (strpos(trim($contents), '{') === 0) {
|
||||||
$output = json_decode($contents, true);
|
$post = json_decode($contents, true);
|
||||||
if ($output === false) {
|
if ($post !== false) {
|
||||||
$output = [];
|
$output = array_merge($output, $post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = array_merge($_GET, $output);
|
return ($filter !== null) ? array_intersect_key($output, array_flip($filter)) : $output;
|
||||||
|
|
||||||
if ($filter !== null) {
|
|
||||||
$output = array_filter($output, function ($key) use ($filter) {
|
|
||||||
return (in_array($key, $filter) === true);
|
|
||||||
}, ARRAY_FILTER_USE_KEY);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -85,17 +85,17 @@ class Response
|
|||||||
/**
|
/**
|
||||||
* Json encode
|
* Json encode
|
||||||
* @param array|\JsonSerializable $value
|
* @param array|\JsonSerializable $value
|
||||||
* @throws \InvalidArgumentException;
|
* @param int $options JSON options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR.
|
||||||
|
* @param int $dept JSON debt.
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function json($value)
|
public function json($value, $options = null, $dept = 512)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (($value instanceof \JsonSerializable) === false && is_array($value) === false) {
|
if (($value instanceof \JsonSerializable) === false && is_array($value) === false) {
|
||||||
throw new \InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
|
throw new \InvalidArgumentException('Invalid type for parameter "value". Must be of type array or object implementing the \JsonSerializable interface.');
|
||||||
}
|
}
|
||||||
|
$this->header('Content-Type: application/json; charset=utf-8');
|
||||||
$this->header('Content-type: application/json');
|
echo json_encode($value, $options, $dept);
|
||||||
echo json_encode($value);
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user