Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
1.8 kB · 69 lines
PHP
at dev
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970<?php
namespace SocialDept\AtpSignals\Events;
use SocialDept\AtpSignals\Contracts\EventContract;use SocialDept\AtpSignals\Enums\SignalCommitOperation;
class CommitEvent implements EventContract{ public SignalCommitOperation $operation;
public function __construct( public string $rev, string|SignalCommitOperation $operation, public string $collection, public string $rkey, public ?object $record = null, public ?string $cid = null, ) { // Convert string to enum if needed $this->operation = is_string($operation) ? SignalCommitOperation::from($operation) : $operation; }
public function isCreate(): bool { return $this->operation === SignalCommitOperation::Create; }
public function isUpdate(): bool { return $this->operation === SignalCommitOperation::Update; }
public function isDelete(): bool { return $this->operation === SignalCommitOperation::Delete; }
public function uri(): string { return "at://{$this->collection}/{$this->rkey}"; }
public static function fromArray(array $data): self { return new self( rev: $data['rev'], operation: $data['operation'], collection: $data['collection'], rkey: $data['rkey'], record: isset($data['record']) ? (object) $data['record'] : null, cid: $data['cid'] ?? null, ); }
public function toArray(): array { return [ 'rev' => $this->rev, 'operation' => $this->operation->value, 'collection' => $this->collection, 'rkey' => $this->rkey, 'record' => $this->record, 'cid' => $this->cid, ]; }}