diff --git a/src/Requests/AddInteractionRequest.php b/src/Requests/AddInteractionRequest.php index 75d3bb1..8afb2a7 100644 --- a/src/Requests/AddInteractionRequest.php +++ b/src/Requests/AddInteractionRequest.php @@ -23,32 +23,32 @@ public function getPayload(): ?array public function setAccountId(int $accountId): self { - return $this->setData('account_id', $accountId); + return $this->setData('account.id', $accountId); } public function getAccountId(): int { - return $this->getData('account_id'); + return $this->getData('account.id'); } public function setSubjectId(int $subjectId): self { - return $this->setData('subject_id', $subjectId); + return $this->setData('subject.id', $subjectId); } public function getSubjectId(): int { - return $this->getData('subject_id'); + return $this->getData('subject.id'); } public function setSubjectTitle(string $subjectTitle): self { - return $this->setData('subject_title', $subjectTitle); + return $this->setData('subject.title', $subjectTitle); } public function getSubjectTitle(): string { - return $this->getData('subject_title'); + return $this->getData('subject.title'); } public function setDescription(string $description): self @@ -89,11 +89,11 @@ public function getFinished(): bool public function setAssignedUserId(int $assignedUserId): self { - return $this->setData('assigned_user_id', $assignedUserId); + return $this->setData('assigned_user.id', $assignedUserId); } public function getAssignedUserId(): int { - return $this->getData('assigned_user_id'); + return $this->getData('assigned_user.id'); } } diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 92f6e42..8c8a7fd 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -11,11 +11,30 @@ abstract class Request extends BaseRequest protected $data = []; /** - * @var mixed $data + * @param mixed $value */ - public function setData(string $key, $data): self + public function setData(string $key, $value): self { - $this->data[$key] = $data; + if ($key === null) { + $this->data = $value; + + return $this; + } + + $data = &$this->data; + $keys = explode('.', $key); + + while (count($keys) > 1) { + $key = array_shift($keys); + + if (!isset($data[$key]) || !is_array($data[$key])) { + $data[$key] = []; + } + + $data = &$data[$key]; + } + + $data[array_shift($keys)] = $value; return $this; } @@ -23,8 +42,25 @@ public function setData(string $key, $data): self /** * @return mixed */ - public function getData(string $key) + public function getData(string $key = null) { - return $this->data[$key] ?? null; + if ($key === null) { + return $this->data; + } + + $data = $this->data; + $keys = explode('.', $key); + + while (count($keys) > 0) { + $key = array_shift($keys); + + if (isset($data[$key]) && (is_array($data[$key]) || count($keys) == 0)) { + $data = $data[$key]; + } else { + $data = null; + } + } + + return $data; } }