Skip to content
docsv0.44.3

SourceReadHandler

`source:read` — returns a raw slice of one source file inside the app root, by line range. The debt this pays (measured on a live cattle run): the agent said, literally, «I don't have a read file tool». Without one, `edit`'s find/replace contract is unusable — a find must match the file VERBATIM, and text remembered or deduced rarely does — so every change fell back to `implement` reconstructing the whole file from memory. Read first, then find/replace exactly what was read. The path discipline is {@see TestHandler}'s: a path that resolves outside the root is refused before anything is opened, because once this is an operation the input no longer comes only from a person typing on their own machine. Two things inside the root are refused too: a file the house keeps a secret in ({@see SecretFiles}), and the running house's STATE under `var/`/`storage/` ({@see SourcePath::isHouseState()}, greenhouse decisions/0618) — this reads SOURCE to edit it, not the sessions, tokens and ledgers the house writes as it runs. Truncation is declared, never silent, and the default slice is small on purpose — ask again with `from` rather than paging a whole file. Not found is `ok:false` with a reason, never an exception (same contract as {@see ValidateHandler}).

SourceReadHandler::__construct()

public function __construct(Milpa\DevTools\Support\RootResolver $roots = new RootResolver()):

Parameters

Parameters of __construct()
NameTypeDescription
$rootsMilpa\DevTools\Support\RootResolver

SourceReadHandler::handle()

public function handle(array $input): array

Reads up to `lines` lines starting at 1-based `from`, with honest accounting: how many lines the file has, how many came back, and whether anything after the slice was left out.

Parameters

Parameters of handle()
NameTypeDescription
$inputarray<string, mixed>