*/ public function all(): array { $stored = $this->options->get(self::OPTION, []); $destinations = []; foreach (is_array($stored) ? $stored : [] as $id => $entry) { if (is_array($entry)) { $destinations[(string) $id] = Destination::fromArray((string) $id, $entry); } } return $destinations; } public function find(string $id): ?Destination { return $this->all()[$id] ?? null; } /** * Save one Destination, minting an id where it has none. * * A ULID like every other id WConvert issues, so an id is never a * sequential integer a page can leak (ADR 0001). * * @param array $settings */ public function save(?string $id, string $type, string $label, ?string $connectionId, array $settings): Destination { $destination = new Destination( $id !== null && $id !== '' ? $id : Ulid::generate(), $type, $label, $connectionId, $settings ); $all = $this->all(); $all[$destination->id] = $destination; $this->write($all); return $destination; } public function delete(string $id): bool { $all = $this->all(); if (!isset($all[$id])) { return false; } unset($all[$id]); $this->write($all); return true; } /** * @param array $all */ private function write(array $all): void { $this->options->set(self::OPTION, array_map( static fn (Destination $destination): array => $destination->toArray(), $all )); } }