fn () => false]); * Zurücksetzen: FailingDisk::restore('archive'). */ class FailingDisk extends FilesystemAdapter { /** @var array */ private static array $originals = []; /** * @param array $hooks */ public function __construct(FilesystemAdapter $inner, private readonly array $hooks) { parent::__construct($inner->getDriver(), $inner->getAdapter(), $inner->getConfig()); } /** * @param array $hooks */ public static function install(string $disk, array $hooks): FilesystemAdapter { /** @var FilesystemAdapter $original */ $original = self::$originals[$disk] ?? Storage::disk($disk); self::$originals[$disk] = $original; Storage::set($disk, new self($original, $hooks)); return $original; } public static function restore(string $disk): void { if (isset(self::$originals[$disk])) { Storage::set($disk, self::$originals[$disk]); unset(self::$originals[$disk]); } } public function exists($path) { return $this->hook('exists', $path, fn () => parent::exists($path)); } public function put($path, $contents, $options = []) { return $this->hook('put', $path, fn () => parent::put($path, $contents, $options)); } public function delete($paths) { return $this->hook('delete', $paths, fn () => parent::delete($paths)); } public function move($from, $to) { return $this->hook('move', $from, fn () => parent::move($from, $to)); } private function hook(string $method, mixed $path, callable $real): mixed { if (isset($this->hooks[$method])) { return ($this->hooks[$method])($path, $real); } return $real(); } }