Documentation
¶
Overview ¶
Package config defines the config/config.yml configuration model.
Index ¶
- Constants
- Variables
- func Declares(declared map[string]any, keys ...string) bool
- func ErrRootWithVirtualHosts(root string) error
- func ValidateMailDeclaration(filename string, declared map[string]any) error
- type Config
- func Load(filename string) (Config, error)
- func New() Config
- func NewTestConfig() Config
- func Overlay(base Config, filename string, forbidden []string, owned string) (Config, map[string]any, error)
- func OverlayBytes(base Config, filename string, data []byte, forbidden []string, owned string) (Config, map[string]any, error)
- func Value(c *Config) Config
- type Flatstack
- type Hooks
- type Mail
- type Routes
- type Server
- type Telemetry
- type Test
- type TestSuite
- type VirtualHost
Constants ¶
const VirtualHostConfigFile = "phpscript.yml"
VirtualHostConfigFile is the file in an application root that configures the virtual host rooted there.
Variables ¶
var DefaultRuntimeConfig []byte
DefaultRuntimeConfig is config/config.yml as it was compiled in. Every default lives in that file and nowhere else, so a file passed with -f is read on top of this one and only has to name what it changes.
Functions ¶
func Declares ¶ added in v0.5.0
Declares reports whether a parsed file named the given key path. Validation needs it to tell a setting a file asked for from one it inherited through Overlay.
func ErrRootWithVirtualHosts ¶ added in v0.6.0
ErrRootWithVirtualHosts is the refusal an application root gets when the configuration lists virtual hosts.
func ValidateMailDeclaration ¶ added in v0.6.0
ValidateMailDeclaration rejects a flat mail block before the typed decode reaches it, and says where to move it.
It reads the generic map because that is the only place the difference is still visible: the decoder can only report that a string is not a struct, which names neither the key nor the fix. Keys and names are checked in a fixed order, so the same file fails on the same line.
Types ¶
type Config ¶
type Config struct {
Runner runner.Options `yaml:"runner"`
Flatstack Flatstack `yaml:"flatstack"`
Routes Routes `yaml:"routes"`
Server Server `yaml:"server"`
Telemetry Telemetry `yaml:"telemetry"`
Test Test `yaml:"test"`
Env []string `yaml:"env"`
// Mail configures the mail servers mail() and `new Mail($name)` deliver
// through, keyed by the name a script asks for.
Mail Mail `yaml:"mail"`
// DocumentRoot is the directory beneath the application root that is
// served over HTTP. It is "public" and almost never worth setting; it
// exists for a site whose tree already names that directory something
// else.
DocumentRoot string `yaml:"document_root"`
// Autoindex answers a directory that has no index page with a listing of
// what is in it, the way nginx's autoindex does. It is off, because
// publishing every file below the document root is a decision a site
// makes and not one it should arrive at by leaving an index.html out.
Autoindex bool `yaml:"autoindex"`
// VirtualHost is the list of sites this server routes by domain. Each
// entry names an application root whose phpscript.yml is the
// configuration that site runs under.
VirtualHost []VirtualHost `yaml:"virtualhost"`
}
Config configures phpscript runtimes and HTTP modules.
func Load ¶ added in v0.6.0
Load reads filename over the embedded defaults, through the same overlay a virtual host and a test suite get. An empty filename is the defaults alone.
func New ¶
func New() Config
New returns the default configuration, which is config/config.yml as it is compiled into the binary. Defaults live in that file and nowhere else, so a file passed with -f is read on top of it and only has to name what it changes.
func NewTestConfig ¶ added in v0.3.0
func NewTestConfig() Config
NewTestConfig returns the default configuration with the parts a test has no use for turned off: a port picked by the kernel, no lifecycle logging, and no recorder, so parallel tests neither collide on a port nor record into each other.
func Overlay ¶ added in v0.5.0
func Overlay(base Config, filename string, forbidden []string, owned string) (Config, map[string]any, error)
Overlay reads filename over base and returns the configuration it describes, together with the keys the file itself named, which is what tells a key it set from one it inherited.
It is the layering every phpscript.yml gets: a file names what it changes and inherits the rest. A missing one is an error rather than a fall back to base, because a tree served under settings nobody wrote is the failure worth avoiding. forbidden names the keys the file may not set and owned says who sets them instead; both are rejected rather than dropped.
func OverlayBytes ¶ added in v0.5.0
func OverlayBytes(base Config, filename string, data []byte, forbidden []string, owned string) (Config, map[string]any, error)
OverlayBytes is Overlay over source already read. A caller holding the file as bytes has its own filesystem to read from: the fixture tree is compiled into the test binary, and a virtual host root is an absolute path no fs.FS spells. filename is only what errors name.
func Value ¶ added in v0.5.0
Value is the configuration a pointer holds, and the zero configuration for a nil one.
Every command constructor takes a *Config so one signature covers all of them, and a command that reads no configuration is handed whatever the caller has. This is what lets the ones that do read it work with a value without each repeating the nil check.
func (Config) PlatformOptions ¶ added in v0.3.0
PlatformOptions returns the platform options `phpscript server` runs under.
There is one recorder and the platform owns it: given these options it builds the tracer, wraps every module in the tracing middleware and mounts the debug front end under Telemetry.Path. phpscript registers no recorder of its own. It observes the interpreter onto the trace that middleware started, so interpreter spans show up on the same front end as the request that caused them.
func (Config) Validate ¶ added in v0.6.0
Validate reports whatever would stop a server from starting under this configuration, checking nothing that would start one.
filename names the file in errors from blocks that carry no name of their own. root is the application root a single-root server would serve, and is refused beside a virtual host list, which names its own.
func (Config) ValidateRoot ¶ added in v0.6.0
ValidateRoot checks a single application root the way ValidateVirtualHosts checks an entry: fs.Sub does not stat, so a missing document root is otherwise a 404 on the first request.
func (Config) ValidateVirtualHosts ¶ added in v0.3.1
ValidateVirtualHosts checks the whole list before any site is built, so a bad entry fails the server rather than one request. Every entry is loaded here, because the document root and the telemetry block two of the checks need come from the site's phpscript.yml and not from the entry.
type Flatstack ¶
type Flatstack struct {
Enabled bool `yaml:"enabled"`
}
Flatstack selects the flat bytecode runtime when enabled.
type Hooks ¶ added in v0.5.0
type Hooks struct {
// Setup runs once before any fixture below this suite root: the schema its
// fixtures query and the rows they read. A failure fails the run before a
// fixture executes, because a suite whose fixtures all fail on missing
// state reports the same thing many times and names none of it.
Setup string `yaml:"setup"`
// Teardown runs once after those fixtures, whether they passed or failed,
// so state a suite created outside its own database is still released by a
// run that ended badly.
Teardown string `yaml:"teardown"`
}
Hooks are the PHP files a test session runs around the fixtures of one suite root. Both are resolved against that root, and both run once per session rather than once per fixture.
They are configuration rather than an annotation because a test session is not a server. @startup, @route and @schedule are scanned out of a source tree by `phpscript server`, which runs them per virtual host or per application root depending on how it is configured; there is no such scope in a fixture run, and a comment in a file that a walk happened to reach is not a contract a suite can be held to.
type Mail ¶ added in v0.6.0
Mail configures the mail servers mail() and `new Mail($name)` deliver through, keyed by the name a script asks for; "default" is what a script naming none gets.
The credentials stay here: nothing a script can call spells a host or a password or reads one back. A site declaring a mail block gets the servers it named and none of the operator's, which docs/configuration.md records.
func (Mail) Validate ¶ added in v0.6.0
Validate checks that every configured server can be delivered through, so a credential the operator got wrong fails the command rather than the first delivery. A @schedule job discovering it at three in the morning is the failure mode worth avoiding.
Servers are checked in name order so the reported one does not depend on map iteration.
type Routes ¶
type Routes struct {
Enabled bool `yaml:"enabled"`
}
Routes controls loading of annotated PHP routes by HTTP servers.
type Server ¶ added in v0.3.0
type Server struct {
// Addr is the address the HTTP server listens on.
Addr string `yaml:"addr"`
// Quiet turns down platform lifecycle logging.
Quiet bool `yaml:"quiet"`
// Modules limits which platform modules load, by name. An empty list
// loads all of them.
Modules []string `yaml:"modules"`
// PidFile is the file the server records its process id in, and the one
// -s reload reads it back from. Empty writes none. The path resolves
// against the working directory, so -s needs the same -w.
PidFile string `yaml:"pid_file"`
}
Server is the YAML spelling of platform.Options: everything a configuration file gets to say about the platform `phpscript server` runs on. The options the platform takes from the process rather than from a file, such as the config filesystem a composed service embeds, are not part of it, and neither is the recorder: that one is the top level telemetry block, applied by Config.PlatformOptions.
type Telemetry ¶ added in v0.3.0
type Telemetry struct {
telemetry.Options `yaml:",inline"`
Driver string `yaml:"driver"`
StoragePath string `yaml:"storage_path"`
}
Telemetry is oida options plus optional durable storage.
type Test ¶ added in v0.5.0
type Test struct {
// Include names a file included ahead of every fixture below this suite
// root, once per session, for the functions and classes the fixtures expect
// to be there: a composer autoloader, a bootstrap file. It is the --include
// flag, which overrides this. A file that is not there is skipped.
Include string `yaml:"include"`
// Hooks are the PHP files the session runs around the fixtures.
Hooks Hooks `yaml:"hooks"`
// Parallel is how many fixtures of one area may run at once, the
// --parallel flag.
Parallel int `yaml:"parallel"`
// Cache is how far a parsed include and a compiled expression travel,
// worker or off, the --cache flag.
Cache string `yaml:"cache"`
// SkipPHP leaves the php binary out of a matrix run, the --skip-php flag.
SkipPHP bool `yaml:"skip_php"`
}
Test configures `phpscript test`. It is the defaults a fixture tree carries for itself, so a suite describes what it needs instead of the command line repeating it on every invocation. A flag still wins: the file describes a tree, and a flag is what an operator typed about this run of it.
Include and Hooks belong to a suite root, the directory holding the file, and apply to the fixtures below it. Parallel, Cache and SkipPHP describe the whole run and are read only from the configuration -f names or the one found above the working directory; a file below the invocation root that sets one fails the run naming the key.
type TestSuite ¶ added in v0.5.0
type TestSuite struct {
// Dir is the suite root, the directory holding the file. It is the
// application root the fixtures below resolve their prelude and their hooks
// against.
Dir string
// Config is the file read over the configuration the run started with.
Config Config
// Declared holds the keys the file itself named, so a caller can tell a
// setting the suite asked for from one it inherited.
Declared map[string]any
}
TestSuite is one phpscript.yml governing a directory of fixtures: where it sits, and the configuration the fixtures below it run under.
func LoadTestSuite ¶ added in v0.5.0
func LoadTestSuite(dir, filename string, data []byte, base Config, forbidden bool) (*TestSuite, error)
LoadTestSuite reads a phpscript.yml already held as bytes over base. The caller does the reading because it owns the filesystem: a fixture tree is compiled into the test binary and reached through an fs.FS, while a run of the command reads the same file off disk.
forbidden decides whether the run-wide keys are refused. The configuration found at or above the invocation root is the run's own and sets them; one discovered below it governs a folder and does not.
type VirtualHost ¶ added in v0.3.1
type VirtualHost struct {
// Domain is the Host headers this entry answers for, separated by
// spaces. Every name reaches the same site, not a copy of it: one
// application root, one configuration, one set of connections and one
// recorder, no matter which name a request arrived under. The usual case
// is a bare domain and its www form, "example.com www.example.com".
//
// The first name is the site's own, the one it is reported under.
Domain string `yaml:"domain"`
// Root is the application root, the directory holding the site's
// phpscript.yml.
Root string `yaml:"root"`
// DocumentRoot is the directory under Root served over HTTP. It defaults
// to public and rarely needs setting: it is here for a site whose tree
// already names that directory something else, not a field an operator is
// expected to fill in.
DocumentRoot string `yaml:"document_root"`
}
VirtualHost routes a set of domains to an application root. The operator owns these fields; everything else about the site comes from the phpscript.yml in Root, which the site's own author writes.
func (VirtualHost) Domains ¶ added in v0.3.1
func (v VirtualHost) Domains() []string
Domains returns every name this entry answers for, in the order Domain lists them, lowercased and without a trailing dot so a Host header compares equal to a configured name.
func (VirtualHost) Load ¶ added in v0.3.1
func (v VirtualHost) Load(base Config) (Config, error)
Load reads Root/phpscript.yml over base and returns the configuration the virtual host runs under, with the document root resolved.
func (VirtualHost) Name ¶ added in v0.3.3
func (v VirtualHost) Name() string
Name is the first name the entry lists. It is what the site is reported under in errors and in the names of the modules it registers, so that a site answering to several names is still one identifiable site.
func (VirtualHost) Normalize ¶ added in v0.3.1
func (v VirtualHost) Normalize() VirtualHost
Normalize rewrites Domain as the list Domains returns, so an entry carries the names a Host header is compared against rather than the spelling the operator used.