MarkerInserter
Deterministic, anchor-based text insertion for AUTO-WIRING a generator's registration snippet into an EXISTING plugin file that already carries the matching `// {marker}` comment anchor (see {@see Markers}) — never a rewrite, never AST surgery: a plain line-splice immediately before the marker line, re-indented to the marker line's own indentation, with the marker line itself always preserved so a later `coa:make` run can insert at it again (F1: "insert at a known anchor, not a * rewrite"). Idempotent-safe by construction: {@see insertBefore()} skips the splice (returns `$contents` unchanged) when the given snippet, trimmed, already appears verbatim in the file — closing the F1 friction ("~57 lines hand-merged") without risking silent duplicate wiring on a re-run of the same `coa:make` command. Pass `$force` to re-insert anyway (mirrors {@see WriteGuard}'s own `--force` semantics).
MarkerInserter::hasMarker()
public function hasMarker(string $contents, string $marker): boolWhether `$contents` carries a `// {$marker}` anchor line (see {@see Markers}).
Parameters
| Name | Type | Description |
|---|---|---|
| $contents | string | |
| $marker | string |
MarkerInserter::insertBefore()
public function insertBefore(string $contents, string $marker, string $snippet, bool $force = false): stringInserts `$snippet` immediately before the `// {$marker}` anchor line inside `$contents`, indenting every line of `$snippet` to match the marker line's own leading whitespace — the marker line is never consumed, so a later call targeting the same marker splices in above the previous insertion(s), oldest first.
Parameters
| Name | Type | Description |
|---|---|---|
| $contents | string | |
| $marker | string | |
| $snippet | string | |
| $force | bool |
Throws
\RuntimeException When `$contents` carries no `// {$marker}` anchor — check
{@see hasMarker()} before calling this.