*/ public function all(): array { $stored = $this->options->get(self::OPTION, []); $entries = []; foreach (is_array($stored) ? $stored : [] as $entry) { if (is_array($entry)) { $entries[] = [ 'destination' => (string) ($entry['destination'] ?? ''), 'lead' => (string) ($entry['lead'] ?? ''), 'error' => (string) ($entry['error'] ?? ''), 'at' => (string) ($entry['at'] ?? ''), ]; } } return $entries; } public function record(string $destinationId, string $leadId, string $error, string $at): void { $entries = $this->all(); array_unshift($entries, [ 'destination' => $destinationId, 'lead' => $leadId, 'error' => mb_substr(DiagnosticSanitizer::message($error), 0, self::ERROR_LENGTH), 'at' => $at, ]); $this->options->set(self::OPTION, array_slice($entries, 0, self::KEPT)); } /** * Remove diagnostics that still identify Leads erased from the log. * * @param list $leadIds */ public function forgetLeads(array $leadIds): void { if ($leadIds === []) { return; } $remove = array_fill_keys($leadIds, true); $this->options->set(self::OPTION, array_values(array_filter( $this->all(), static fn (array $entry): bool => !isset($remove[$entry['lead']]) ))); } }