Skip to content

Commit

Permalink
Several default values can now be defined
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jul 16, 2016
1 parent e061dbd commit c2ace26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,8 @@ ADDED:

CHANGED:

- Default values can now be defined to several methods of `Request`

REMOVED:

FIXED:
Expand Down
21 changes: 12 additions & 9 deletions src/JsonApi/Request/Request.php
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c2ace26

Please sign in to comment.