Compare commits

...

4 Commits

Author SHA1 Message Date
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
2 changed files with 13 additions and 6 deletions
+12 -5
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
* @throws \InvalidArgumentException;
*/
public function json(array $value)
public function json($value)
{
$this->header('Content-Type: application/json');
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');
echo json_encode($value);
die();
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;