Documentation
¶
Overview ¶
Package mapmap holds a read-only map with a request-scoped layer of edits over it.
A superglobal is read far more often than it is written, and what it reads is the request, which does not change while the request is served. Rendering it into a *model.Array copies every entry into a second representation on the way in, whether or not the script names the variable. A MapMap answers from the request instead, and holds only what a script wrote.
The edits are request-scoped, so their map comes from a pool and goes back cleared rather than freed.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapMap ¶
type MapMap struct {
// contains filtered or unexported fields
}
MapMap reads through a Source and writes to a layer of its own.
Read answers the layer first, so a script that assigns to a key sees what it assigned; the source is left as it was and stays shared. Nothing is copied out of the source until something asks for the whole thing.
func (*MapMap) Range ¶
Range visits the source in its own order, then the keys only the layer holds.
A key the layer overwrote is visited in the source's position with the written value, so assigning to an existing key does not move it.
type MapSource ¶
MapSource reads a plain map. It is the source for a run with no request behind it, which is every CLI invocation.
type RequestSource ¶
RequestSource derives the CGI names from the request itself, so serving one builds no map.
Extra carries the names the request cannot answer on its own, which are the ones a caller computed: the clock for REQUEST_TIME, and whatever the host decided about the scheme behind a proxy. It is a Source of its own so a caller passes the map it already has rather than copying it into another. It is read, never written, and wins over a derived name.
type Source ¶
type Source interface {
// Get answers the value of key and whether the source holds it.
Get(key string) (any, bool)
// Len counts the keys Range would visit.
Len() int
// Range visits every key in the source until fn answers false.
Range(fn func(key string, value any) bool) bool
}
Source is the read-only half of a MapMap: the request, or a map built for a run that has no request behind it.
A source is read while the request is served and is never written, so one may be shared by every MapMap over it.
type ValueSource ¶
ValueSource reads a map whose values are already PHP values, which is what a superglobal carrying nested data needs: a query string decodes `a[]=1&a[]=2` to an array under one name, and no map of strings can hold that.