Skip to content
docsv0.24.0

WriteGuard

Filesystem safety for generators: refuses to clobber an existing file unless `--force`, and creates parent directories on write. `assertWritable()` is called for every planned file up front so a blocked target aborts the whole `coa:make` run before anything is written.

WriteGuard::assertWritable()

public function assertWritable(string $path, bool $force, bool $merge = false): void

Throws unless `$path` is free to write: absent, `$force` is true, or `$merge` is true.

Parameters

Parameters of assertWritable()
NameTypeDescription
$pathstring
$forcebool
$mergeboolSet from the originating {@see PlannedFile::$merge} — a MARKER-BASED, idempotent-safe merge into an already-existing plugin file (see {@see MarkerInserter}) is exactly the "safe to overwrite even without * `--force`" case this guard exists to distinguish from an accidental clobber of unrelated hand-written content.

WriteGuard::write()

public function write(string $path, string $contents): void

Writes `$contents` to `$path`, creating parent directories as needed.

Parameters

Parameters of write()
NameTypeDescription
$pathstring
$contentsstring