From 1529f470fa462d7f6ffbee08ca9f585d431de974 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 5 Sep 2022 15:07:16 +1000 Subject: [PATCH] Add __set method to Job and auto-initialize _data, update Message to check for a Team if the message is being used in a slack API --- src/Jobs/Job.php | 9 ++++++++- src/Message.php | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Jobs/Job.php b/src/Jobs/Job.php index fc8bb95..f17a3dd 100644 --- a/src/Jobs/Job.php +++ b/src/Jobs/Job.php @@ -7,6 +7,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Arr; +use Illuminate\Support\Collection; abstract class Job implements ShouldQueue { @@ -23,14 +24,20 @@ abstract class Job implements ShouldQueue use InteractsWithQueue, Queueable, SerializesModels; - protected $_data = []; + protected Collection $_data; public function __get($key) { + if (! isset($this->_data)) + $this->_data = collect(); + return Arr::get($this->_data,$key); } public function __set(string $key,$value) { + if (! isset($this->_data)) + $this->_data = collect(); + return $this->_data->put($key,$value); } } \ No newline at end of file diff --git a/src/Message.php b/src/Message.php index 82df0bd..2b7cc86 100644 --- a/src/Message.php +++ b/src/Message.php @@ -160,6 +160,9 @@ final class Message extends BlockKit if ($this->_data->get('blocks') && $this->_data->get('attachments')) throw new SlackSyntaxException('Message cannot have blocks and attachments.'); + if ((! isset($this->o)) || (! $this->o->team)) + throw new SlackSyntaxException('Message needs to have a user or a channel to work out the team.'); + $api = $this->o->team->slackAPI(); if ($this->ephemeral) {