stave.dev

Configuration & Wording

Configuration is PHP constants read from .ini files. So is every piece of text a site may want to change.

Constants From .ini Files

There is no config object and no config() helper. Application::defineConstants() reads .ini files and calls define() for each key, and code uses the constant by name:

PRIMARY_DOMAIN=example.com

[mail]
NOTIFY_EMAIL="you@example.com"
$link = "https://" . PRIMARY_DOMAIN . "/auth/token";

Sections such as [mail] only group keys for the reader. Files are parsed without sections, so every key in every file shares one namespace.

Read Order

defineConstants() in core/Application.php reads, in this order:

# Source Read by
1 The site's wording, app/strings/*.ini Strings::loadSite()
2 Every app/config/*.ini, then each .ini in core/skeleton/config/ the site has no file of the same name for Application::configFiles()
3 The SITE_NAME and SITE_SHORT_NAME fallbacks Strings::defineSiteFallbacks()
4 Core's default wording, core/skeleton/strings/*.ini Strings::loadDefaults()
5 The array passed to defineConstants(), if any define() per key
6 The requested module's strings/*.ini, then its config.ini, then every file in its config/, when the module is on Application::loadModuleConfig()

After the files: when TIMEZONE is defined and not empty it becomes PHP's default timezone (an invalid value is logged). The afterConstants plugin hook fires last.

The First Definition Wins

A constant cannot be redefined, so the order above is the precedence: a key in app/strings/ beats the same key in app/config/, which beats a module's.

Skeleton Defaults

core/skeleton/config/ holds two files core reads when the site has no file of the same name: constants.ini (DEV_SUBNET=-) and error_codes.ini. The fallback is per file, not per key.

A site constants.ini replaces the skeleton's

zero-init.sh gives a new site its own app/config/constants.ini, so the skeleton's is no longer read, and DEV_SUBNET comes from the [dev] section of app/config/config.ini. Nothing in core reads DEV_SUBNET at present (see Development Mode), so a site that leaves the key out still runs.

Module Configuration

A module's constants exist before its class is loaded, simply because the files are in its folder:

File Holds
modules/{Module}/config.ini The module's constants
modules/{Module}/config/* The same, one file per concern
modules/{Module}/config-tmpl/ A copy of each config file with the site's values blanked. config.ini and config/ are not committed; config-tmpl/ is (core/modules/Module/README)

The Config Templates

core/skeleton/config-templates/ holds the blank files zero-init.sh copies into app/config/. That folder holds settings and secrets and is not committed.

config.ini

Key Template value What it is
PRIMARY_DOMAIN example.com The site's domain. The links in sign-in mail, the OAuth redirect URI and the default sender address are built from it
ADMIN_DOMAIN admin.example.com In the template; no PHP in core reads it
ENFORCE_HTTPS false In the template; no PHP in core reads it
WEB_ROOT /var/www/html/example.com/www Filesystem root of the public web directory, no trailing slash. Asset links are created under it (Assets)
ACCEPTED_SUBDOMAINS blank In the template; no PHP in core reads it
DEV_SUBNET "192.168.1." Not read at present. It is the string the commented-out DEVMODE check looks for in the client address (see Development Mode)
MAIL_FROM blank Address mail is sent from. Blank means noreply@ + PRIMARY_DOMAIN (core/lib/Mail/Mail.php)
MAIL_CAPTURE_DIR blank A folder, absolute or relative to the site root. When set, each message is written there as a file and nothing is sent. The files hold live sign-in links
NOTIFY_EMAIL "you@example.com" Where Mail::sendEmailToAdmin() and access requests are sent

database.ini

Key Template value What it is
HOSTlocalhostDatabase server
NAMEblankDatabase name. For sqlite, the file path or :memory:. Required
USER, PASSblankCredentials. USER is required unless the driver is sqlite; PASS may be blank
DB_DRIVERmysqlPDO driver: mysql, pgsql or sqlite. Required: there is no default
DB_PORTblankBlank leaves the port out of the DSN, so the driver uses its own default
DB_CHARSETblankClient encoding. Blank means utf8mb4 on mysql and the server default on pgsql

Database::getConnection() builds the DSN from these constants on its first call (Models & Database). With DB_DRIVER, NAME or USER blank or absent, Database::isConfigured() is false and no connection is attempted: the call throws Database is not configured and logs nothing (core/Database.php). A site with no database leaves the template's NAME and USER blank.

constants.ini and others

Key Where What it is
SESSION_REGENERATE_INTERVAL constants.ini, 1800 Seconds after which a session gets a new id. Left out or blank, 1800; 0 means never. Also in core/skeleton/config/constants.ini, for a site with no constants.ini of its own
TIMEZONE Not in a template; add it to any config file PHP's default timezone. Unset, PHP keeps what php.ini gave it
ZERO_LOG_LEVEL, ZERO_LOG_LEVEL_INT Not in a template The lowest level Console writes, by name or by index. With neither, everything is written (core/Console.php)
ENTITY_SITE_DIR Not in a template Where the site's own entity classes are, when not entity/ (Application::classFile())

allowed-ips.lst, the fourth template, is not a config file: it lists the clients that are never banned (Security).

The session check runs at the end of defineConstants(), once the interval is known (Application::regenerateAgedSession()). What happens to the replaced session is on Security.

Key Constants

Constant Defined in Is
ZERO_ROOTindex.phpThe site root, the folder that holds core/
ROOT_PATHindex.phpThe parent of ZERO_ROOT
MODULE_PATHindex.phpThe site's modules directory
VIEW_PATHindex.phpThe site's frame folder, app/frontend/frame/
WEB_ROOTapp/config/config.iniThe public web root
SITE_NAME, SITE_SHORT_NAMEapp/strings/ or the fallbackThe site's name
DEVMODENothing, at presentNot defined (see Development Mode)

Wording

Text a site may want to change is not written into views. It is constants too, from strings/*.ini files read by Zero\Core\Strings.

The Site's Wording

app/strings/*.ini is read before any config file. zero-init.sh copies in site.ini:

; The site's own wording. Repeat any module string key here to override it.
; Wrap each value in double quotes (see core/modules/Module/README).
SITE_NAME="My Zero App"
; Wording the skeleton's frames show. Core defines these English values for any key a site leaves out.
SITE_HOME="Home"
SITE_SIGN_IN="Sign in"
SITE_SIGN_OUT="Sign out"
SITE_ADMIN="Admin"
SITE_SKIP_TO_CONTENT="Skip to content"
SITE_OR="or"
; %s is the provider's name
SITE_SIGN_IN_WITH="Sign in with %s"

A Module's Wording

A module ships its defaults in {Module}/strings/*.ini. Each key carries the module's name in upper snake case as a prefix: AUTH_, USER_, ADMIN_.

Strings::loadModule() defines only the keys not yet defined. The site's strings were read first, so a site overrides any module string by repeating its key:

USER_LOGIN_HEADING="Sign in to %s"
USER_LOGIN_HEADING="Welcome back to %s"
A module's strings load Where
For the module the request names Application::loadModuleConfig()
For the module being built; a submodule loads its parent's Module::__construct()
For any other module, when code asks Strings::loadModule('Name')

A module that is off, or does not exist, loads nothing. Calling loadModule() again is harmless.

Quoting

Strings files are parsed with INI_SCANNER_RAW: a value is taken literally. Wrap each value in double quotes.

KEY="We'll email you a link; it says "hi" = done."

Strings That Take a Value

A string that takes a value holds %s where the value goes. Fill it with Strings::fill(), never sprintf():

<h2><?= htmlspecialchars(\Zero\Core\Strings::fill(USER_LOGIN_HEADING, SITE_SHORT_NAME), ENT_NOQUOTES) ?></h2>

sprintf() throws on a percent sign it does not know, so a site that words a heading "Save 50% at %s" would break the page. fill(string $text, string ...$values) replaces each %s in order and leaves every other percent sign as written. A %s with no value left becomes an empty string.

Development Mode

DEVMODE is not defined at present. The block in Application::defineConstants() that defines it is commented out, and nothing reads DEV_SUBNET (core/Application.php).

Core tests the constant with defined('DEVMODE') && DEVMODE, so every such check takes its production branch. Write your own checks the same way: a bare DEVMODE is an undefined constant, which PHP 8 throws an Error for.

Uncommenting the block restores the check: DEVMODE becomes true when $_SERVER['REMOTE_ADDR'] contains the string DEV_SUBNET. It is a substring match (str_contains()), not CIDR: "192.168.1." matches every 192.168.1.* address. The skeleton's default, DEV_SUBNET=-, matches no address. With DEVMODE true: