diff --git a/CHANGELOG.md b/CHANGELOG.md index 9455be4c..6c499451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ADDED: CHANGED: +- Default values can now be defined to several methods of `Request` + REMOVED: FIXED: diff --git a/src/JsonApi/Request/Request.php b/src/JsonApi/Request/Request.php index c7ec489e..da51b10a 100644 --- a/src/JsonApi/Request/Request.php +++ b/src/JsonApi/Request/Request.php @@ -441,7 +441,7 @@ public function getFilteringParam($param, $default = null) /** * @param string $name * @param mixed $default - * @return array|string|null + * @return array|string|mixed */ public function getQueryParam($name, $default = null) { @@ -477,28 +477,31 @@ protected function initializeParsedQueryParams() } /** - * @return array|null + * @param mixed $default + * @return array|mixed */ - public function getResource() + public function getResource($default = null) { $body = $this->getParsedBody(); - return isset($body["data"])? $body["data"] : null; + return isset($body["data"])? $body["data"] : $default; } /** - * @return string|null + * @param mixed $default + * @return string|mixed */ - public function getResourceType() + public function getResourceType($default = null) { $data = $this->getResource(); - return isset($data["type"]) ? $data["type"] : null; + return isset($data["type"]) ? $data["type"] : $default; } /** - * @return string|null + * @param mixed $default + * @return string|mixed */ - public function getResourceId() + public function getResourceId($default = null) { $data = $this->getResource();