db->fetchOne('SELECT * FROM did_doc WHERE did = ?', [$did]); if ($row === null) { throw new DidDocEntryNotFoundException(); } $doc = json_decode(Row::str($row, 'doc_json'), true, 512, JSON_THROW_ON_ERROR); assert(is_array($doc)); /** @var array $doc */ return new DidDocEntry( did: Row::str($row, 'did'), doc: $doc, updatedAt: new DateTimeImmutable(Row::str($row, 'updated_at')), ); } /** * @param array $doc */ public function set(string $did, array $doc): void { $this->db->execute( 'INSERT INTO did_doc (did, doc_json, updated_at) VALUES (?, ?, ?) ON CONFLICT(did) DO UPDATE SET doc_json = excluded.doc_json, updated_at = excluded.updated_at', [ $did, json_encode($doc, JSON_THROW_ON_ERROR), (new DateTimeImmutable())->format(DATE_ATOM), ] ); } public function has(string $did): bool { return $this->db->fetchOne('SELECT 1 FROM did_doc WHERE did = ?', [$did]) !== null; } public function clear(string $did): void { $this->db->execute('DELETE FROM did_doc WHERE did = ?', [$did]); } public function clearAll(): void { $this->db->pdo()->exec('DELETE FROM did_doc'); } }