diff --git a/Message/RequestAbstract.php b/Message/RequestAbstract.php index 306f965f9..6247ccbd5 100644 --- a/Message/RequestAbstract.php +++ b/Message/RequestAbstract.php @@ -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. *