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

This commit is contained in:
Deon George 2022-09-05 15:07:16 +10:00
parent 905c207956
commit 1529f470fa
2 changed files with 11 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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) {