config

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config defines the config/config.yml configuration model.

Index

Constants

View Source
const VirtualHostConfigFile = "phpscript.yml"

VirtualHostConfigFile is the file in an application root that configures the virtual host rooted there.

Variables

View Source
var DefaultRuntimeConfig []byte

Functions

func Declares added in v0.5.0

func Declares(declared map[string]any, keys ...string) bool

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.

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"`

	// SMTP configures the sender mail() delivers through. Absent, mail()
	// still exists and fails catchably naming the missing configuration. A
	// virtual host overlays its own smtp block over the server's, so each
	// site may deliver through its own host.
	SMTP smtp.Config `yaml:"smtp"`

	// 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 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.

It is the layering every phpscript.yml gets: the file is unmarshalled over an already populated struct, so it only has to name what it changes and inherits the rest. A virtual host reads its site's file over the operator's, and a test suite reads its folder's file over the one the run started with.

A missing file is an error rather than a fall back to base. The file is what the caller went looking for, and a tree served or tested under settings its author never wrote is the failure mode worth avoiding.

forbidden names the keys the file may not set, and owned is the clause saying who sets them instead. They are rejected rather than dropped, so nobody is left believing a key took effect. The declared map is what tells a key the file named from one it inherited, which is what a check on an inherited default would otherwise get wrong.

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

func Value(c *Config) Config

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

func (c Config) PlatformOptions() (*platform.Options, error)

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) ValidateVirtualHosts added in v0.3.1

func (c Config) ValidateVirtualHosts() error

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 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"`
}

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.

func (Server) Options added in v0.3.0

func (s Server) Options() *platform.Options

Options returns the platform options this block describes, with no recorder configured. Callers want Config.PlatformOptions, which adds one.

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.

func (Telemetry) Resolved added in v0.3.0

func (t Telemetry) Resolved() (telemetry.Options, error)

Resolved returns oida options with storage applied.

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.

func (Test) Validate added in v0.5.0

func (t Test) Validate(filename string) error

Validate rejects a test block whose values name nothing the run can act on.

Whether a hook file exists is not checked here, because the file lives in the caller's filesystem rather than on disk. The run reports a missing hook when it goes to execute it.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL