You've already forked php-auth
generated from siteworxpro/Php-Template
Some checks failed
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Failing after 1m19s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m9s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Failing after 1m19s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 1m34s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Failing after 1m20s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Failing after 12s
100 lines
2.1 KiB
PHP
100 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\App\Async\Messages;
|
|
|
|
use Siteworxpro\App\Async\Queues\DefaultQueue;
|
|
use Siteworxpro\App\Async\Queues\Queue;
|
|
use Siteworxpro\App\Helpers\Ulid;
|
|
use Siteworxpro\App\Services\Facades\Broker;
|
|
|
|
abstract class Message implements \Serializable
|
|
{
|
|
protected string $id = '';
|
|
|
|
protected string $uniqueId;
|
|
|
|
protected array $payload;
|
|
|
|
protected int $timestamp;
|
|
|
|
protected string $queue = '';
|
|
|
|
protected const string DEFAULT_QUEUE = DefaultQueue::class;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->uniqueId = Ulid::generate();
|
|
$this->timestamp = time();
|
|
}
|
|
|
|
protected function getQueue(): Queue
|
|
{
|
|
if ($this->queue === '') {
|
|
$this->queue = static::DEFAULT_QUEUE;
|
|
}
|
|
|
|
return new $this->queue();
|
|
}
|
|
|
|
public function getId(): string
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* @param string $id
|
|
*/
|
|
public function setId(string $id): void
|
|
{
|
|
$this->id = $id;
|
|
}
|
|
|
|
public function getPayload(): array
|
|
{
|
|
return $this->payload;
|
|
}
|
|
|
|
public function getTimestamp(): int
|
|
{
|
|
return $this->timestamp;
|
|
}
|
|
|
|
public function __serialize(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'payload' => $this->payload,
|
|
'timestamp' => $this->timestamp,
|
|
'queue' => $this->queue,
|
|
];
|
|
}
|
|
|
|
public function __unserialize(array $data): void
|
|
{
|
|
$this->id = $data['id'];
|
|
$this->payload = $data['payload'];
|
|
$this->timestamp = $data['timestamp'];
|
|
$this->queue = $data['queue'];
|
|
}
|
|
|
|
public function serialize(): string
|
|
{
|
|
return serialize($this);
|
|
}
|
|
|
|
public function unserialize(string $data): Message
|
|
{
|
|
$unserializedData = unserialize($data, ['allowed_classes' => [Message::class]]);
|
|
|
|
$this->id = $unserializedData['id'];
|
|
$this->uniqueId = $unserializedData['uniqueId'];
|
|
$this->payload = $unserializedData['payload'];
|
|
$this->timestamp = $unserializedData['timestamp'];
|
|
$this->queue = $unserializedData['queue'];
|
|
|
|
return $this;
|
|
}
|
|
}
|