Compare commits

...

8 Commits

Author SHA1 Message Date
Simon Sessingø de14a957d5 Merge pull request #343 from skipperbent/v2-development
Version 2.6.8.1
2017-12-17 10:40:26 +01:00
Simon Sessingo c1c25e19ff Enabled fallback _method for every request-type. 2017-12-17 10:38:13 +01:00
Simon Sessingø d61cbb73e5 Merge pull request #338 from skipperbent/v2-development
Version 2.6.8
2017-12-16 12:53:07 +01:00
Simon Sessingo dc7faf52c0 Bugfixes
- Fixed filtering for get-inputs in all method.
- Fixed utf-8 header issue for response()->json() method (issue: #333).
2017-12-16 12:50:48 +01:00
Simon Sessingø 29ab0e85ae Merge pull request #286 from skipperbent/v2-development
Router->json now accepts either array or \JsonSerializable (issue: #284)
2017-08-31 13:05:20 +02:00
Simon Sessingø 539e905b45 Router->json now accepts either array or \JsonSerializable (issue: #284) 2017-08-31 12:01:49 +01:00
Simon Sessingø 0ab15839a9 Merge pull request #216 from skipperbent/v2-development
Fixed: replace empty parameter-values with null.
2017-02-12 20:47:47 +01:00
Simon Sessingø 5977efc942 Fixed: replace empty parameter-values with null. 2017-02-12 20:45:56 +01:00
4 changed files with 20 additions and 21 deletions
+5 -13
View File
@@ -267,29 +267,21 @@ class Input
*/
public function all(array $filter = null)
{
$output = $_POST;
$output = $_GET;
if ($this->request->getMethod() === 'post') {
$contents = file_get_contents('php://input');
if (strpos(trim($contents), '{') === 0) {
$output = json_decode($contents, true);
if ($output === false) {
$output = [];
$post = json_decode($contents, true);
if ($post !== false) {
$output = array_merge($output, $post);
}
}
}
$output = array_merge($_GET, $output);
if ($filter !== null) {
$output = array_filter($output, function ($key) use ($filter) {
return (in_array($key, $filter) === true);
}, ARRAY_FILTER_USE_KEY);
}
return $output;
return ($filter !== null) ? array_intersect_key($output, array_flip($filter)) : $output;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ class Request
$this->host = $this->getHeader('http-host');
$this->uri = $this->getHeader('request-uri');
$this->input = new Input($this);
$this->method = strtolower($this->input->get('_method', $this->getHeader('request-method'), 'post'));
$this->method = strtolower($this->input->get('_method', $this->getHeader('request-method')));
}
protected function parseHeaders()
+13 -6
View File
@@ -1,4 +1,5 @@
<?php
namespace Pecee\Http;
class Response
@@ -82,14 +83,20 @@ class Response
}
/**
* Json encode array
* @param array $value
* Json encode
* @param array|\JsonSerializable $value
* @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(array $value)
public function json($value, $options = null, $dept = 512)
{
$this->header('Content-Type: application/json');
echo json_encode($value);
die();
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.');
}
$this->header('Content-Type: application/json; charset=utf-8');
echo json_encode($value, $options, $dept);
exit(0);
}
/**
+1 -1
View File
@@ -124,7 +124,7 @@ abstract class Route implements IRoute
/* Only take matched parameters with name */
foreach ($parameters[1] as $name) {
$values[$name] = isset($matches[$name]) ? $matches[$name] : null;
$values[$name] = (isset($matches[$name]) && $matches[$name] !== '') ? $matches[$name] : null;
}
return $values;