Add getter for json and list data

This commit is contained in:
Dennis Eichhorn 2018-09-15 14:32:37 +02:00
parent 23f31d359a
commit 378a569316

View File

@ -172,6 +172,51 @@ abstract class RequestAbstract implements MessageInterface
return $this->data[$key] ?? null;
}
/**
* Get data.
*
* @param mixed $key Data key
*
* @return array
*
* @since 1.0.0
*/
public function getDataJson($key) : array
{
$key = \mb_strtolower($key);
if (!isset($this->data[$key])) {
return [];
}
$json = \json_decode($this->data[$key]);
return $json === false ? [] : $json;
}
/**
* Get data.
*
* @param mixed $key Data key
* @param string $delim Data delimiter
*
* @return array
*
* @since 1.0.0
*/
public function getDataList($key, string $delim = ',') : array
{
$key = \mb_strtolower($key);
if (!isset($this->data[$key])) {
return [];
}
$list = \explode($delim, $this->data[$key]);
return $list === false ? [] : $json;
}
/**
* Get data based on wildcard.
*