path(), json_encode([ 'pct' => $pct, 'step' => $step, 'text' => $text, 'ts' => time(), ], JSON_UNESCAPED_UNICODE)); } /** * Fehlerzustand: pct = -1 unterscheidet ihn eindeutig von „0 % erledigt“. */ public function fail(string $text): void { $this->set(-1, 'error', $text); } /** * @return array{pct: int, step: string, text: string, ts: int} */ public function get(): array { $data = json_decode((string) @file_get_contents($this->path()), true); if (! is_array($data) || ! isset($data['pct'], $data['step'])) { return ['pct' => 0, 'step' => 'idle', 'text' => '', 'ts' => 0]; } return [ 'pct' => (int) $data['pct'], 'step' => (string) $data['step'], 'text' => (string) ($data['text'] ?? ''), 'ts' => (int) ($data['ts'] ?? 0), ]; } public function isRunning(): bool { $progress = $this->get(); return ! in_array($progress['step'], ['idle', 'done', 'error'], true) && time() - $progress['ts'] < self::STALE_AFTER_SECONDS; } public function clear(): void { @unlink($this->path()); } private function path(): string { return $this->file ?? storage_path('.update-progress'); } }