Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
2.1 kB · 84 lines
PHP
at dev
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485<?php
namespace SocialDept\AtpSignals\Events;
use SocialDept\AtpSignals\Contracts\EventContract;
class SignalEvent implements EventContract{ public function __construct( public string $did, public int $timeUs, public string $kind, // 'commit', 'identity', 'account' public ?CommitEvent $commit = null, public ?IdentityEvent $identity = null, public ?AccountEvent $account = null, ) { }
public function isCommit(): bool { return $this->kind === 'commit'; }
public function isIdentity(): bool { return $this->kind === 'identity'; }
public function isAccount(): bool { return $this->kind === 'account'; }
public function getCollection(): ?string { return $this->commit?->collection; }
public function getRecord(): ?object { return $this->commit?->record; }
public function getOperation(): ?\SocialDept\AtpSignals\Enums\SignalCommitOperation { return $this->commit?->operation; }
public static function fromArray(array $data): self { $commit = isset($data['commit']) ? CommitEvent::fromArray($data['commit']) : null;
$identity = isset($data['identity']) ? IdentityEvent::fromArray($data['identity']) : null;
$account = isset($data['account']) ? AccountEvent::fromArray($data['account']) : null;
return new self( did: $data['did'], timeUs: $data['time_us'], kind: $data['kind'], commit: $commit, identity: $identity, account: $account, ); }
public function toArray(): array { return [ 'did' => $this->did, 'time_us' => $this->timeUs, 'kind' => $this->kind, 'commit' => $this->commit?->toArray(), 'identity' => $this->identity?->toArray(), 'account' => $this->account?->toArray(), ]; }}