adt / configurator
Extended nette/configurator
Requires
- ext-ctype: *
- ext-sodium: *
- josegonzalez/dotenv: ^4.0
- nette/bootstrap: ^3.2
- tracy/tracy: ^2.9
Requires (Dev)
- adt/error-logger: ^3.4.1
- phpunit/phpunit: ^11.5 | ^12.0 | ^13.0
Suggests
- adt/error-logger: ADT\Bootstrap installs it and sends errors of production by e-mail
Provides
None
Conflicts
None
Replaces
None
- dev-master
- v7.7.0
- v7.6.0
- v7.5.0
- v7.4.0
- v7.3.0
- v7.2.1
- v7.2.0
- v7.1.0
- v7.0.0
- 6.x-dev
- v6.7.1
- v6.7.0
- v6.6.0
- v6.5.0
- v6.4.0
- v6.3.0
- v6.2.0
- v6.1.1
- v6.1.0
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0
- v5.4.1
- v5.4
- 5.3.4
- v5.3.3
- v5.3.2
- v5.3.1
- v5.3
- v5.2.1
- v5.2
- v5.1.1
- v5.1
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0
- v4.3
- v4.2
- v4.1.1
- v4.1
- v4.0.1
- v4.0
- v3.0.1
- v3.0
- v2.2
- v2.1
- v2.0
- v1.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1
- v1.0
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4
- v0.3
- v0.2
- v0.1
- dev-loadEnv-fix-order
- dev-app-debug
- dev-f-allows-to-have-numeric-string-with-zero-on-start-as-string
- dev-improvements
This package is auto-updated.
Last update: 2026-11-28 09:47:18 UTC
README
Extended nette/configurator.
Installation
composer require adt/configurator
Usage
$configurator = new Configurator();
$configurator->loadEnv(__DIR__ . '/..', ['.env.common']);
$configurator
->addDeveloper(json_decode($_ENV['NETTE_DEVELOPERS'], true))
->setDebugMode((bool) $_ENV['NETTE_DEBUG']);
$configurator
->setConfigDirectory(__DIR__ . '/config')
->addConfig('common')
->addConfig('interface/' . php_sapi_name())
->addConfig('stage/' . $_ENV['STAGE'])
->addConfig(explode(',', $_ENV['NETTE_ENV']))
->addConfig(Configurator::isCli() && Configurator::get('country') ? 'cli-country' : null)
->addConfig(Configurator::get('country') ? 'env/' . $_ENV['STAGE'] . '-' . Configurator::get('country') : null)
->addConfig($_ENV['NETTE_TEST'] ? 'test' : null);
Bootstrap of a project
ADT\Bootstrap is the bootstrap of the AppsDevTeam web projects (sandbox layout: .env, app/,
config/, log/, temp/ in one root). The project's class only adds what is its own:
namespace App; class Bootstrap extends \ADT\Bootstrap { // deprecations of the vendor on the current PHP: out of strict mode of Tracy protected bool $strictDeprecations = false; protected function init(): void { // before the container (static registrations of the project) CzechValidationMessages::register(); } protected function addConfigs(string $interface): void { // after common, interface/<ui|console>, stage/<STAGE>, APP_ENV and tenant configs, before sandbox and test $this->configurator->addConfig(\ADT\Configurator::isCli() ? 'cli-extra' : null); } }
new \App\Bootstrap() (root = parent of the directory of the class) then bootUI() in
www/index.php, bootConsole() in bin/console and the test bootstrap. It does:
loadEnv(),handlePreprodAccess()andhandleMaintenance()(see below) in the constructorsrc/defaults.neonof the package beforeconfig/common.neon(with nette/http only): noX-Powered-By, CSPobject-src 'none',base-uri 'none',frame-ancestors 'self'- the project overrides them incommon.neon,script-srcstays in the project (it depends on its templates)- debug mode: console
APP_DEBUG, webAPP_DEBUGor a developer token (see Debug mode on servers);protected bool $debugInTests = falseruns web requests in test mode (APP_TEST, nginx on port 1420) in production mode - for tests that check the error page or the absence of request data in the output (the Tracy bar echoes the request headers); error page of productionsrc/error.phtmlof this package (500, AJAX gets just the text),app/error.phtmlof the project replaces it - Tracy (
log/),ADT\ErrorLoggerwhen adt/error-logger is installed ($errorEmail, null = off, e-mails only in production;ERROR_EMAILof.envoverrides the recipient per stage, empty = no e-mails, e.g. CI),temp/, parametersrootDir,appDir,wwwDir - secrets hidden in the Tracy log (HTML and
.md, the attachments of ErrorLogger e-mails) and on the BlueScreen: a scrubber hides every key matching$sensitiveKeys(*PASS*,*SECRET*,*TOKEN*,*_KEY*,*SALT*,*DSN*,*AUTH*,APP_DEVELOPERS, cookies and the session ID,app-debug,MAINTENANCE_BYPASS...) -$_ENVand$_SERVERcarry the whole.envof the container - and the value of every cookie, whatever its name (remember-me and similar logins). A project extends the pattern by overriding the property; a scrubber set by the project before is kept. Not covered: the.mdreport of plain Tracy prints request headers and unnamed call arguments raw (scrubbed only by ErrorLogger ≥ 3.4, which writes its own), and the URL (report title,REQUEST_URI,QUERY_STRING, the line ofexception.log) keeps secrets of the query string (tests/BootstrapWebTest.php) - configs
common,interface/<ui|console>,stage/<STAGE>,APP_ENV(comma-separated), tenant configs,addConfigs(),sandbox(see Sandbox of a restore drill),test(APP_TESTin.envor env) - tenants (several projects in one code base):
APP_ENV=project/<name>(config/project/<name>.neon) addsconfig/project.neon(shared by the tenants) andconfig/env/<STAGE>-<name>.neon($tenantGroup, null = off) - in test mode the parameters of adt/make
make test:testDbNamefrom envTEST_DB_NAME(a suite with its own database) andtestShardSuffix(''or_<part>from envTEST_SHARDor cookietest_shard) for a suite split into parts
Sandbox of a restore drill
The restore drill of server-management-scripts (restore.sh) restores a production release with
its data into an isolated VM zone and switches it into a sandbox by .env.sandbox (merged into
.env of the release and passed to the containers). APP_SANDBOX=1 makes ADT\Bootstrap:
- send all outgoing HTTP to a dead proxy
SANDBOX_HTTP_PROXY(e.g.http://127.0.0.1:9, exceptSANDBOX_NO_PROXY) - clients with a hardcoded URL and credentials from the restored database would otherwise call live APIs on behalf of the customers; without the proxy the application does not start - send no error e-mails (production mode over production data)
- add
config/sandbox.neonof the project (optional) after all its configs - test endpoints of payment gateways and other services with a configured URL
APP_SANDBOX=1
SANDBOX_HTTP_PROXY=http://127.0.0.1:9
SANDBOX_NO_PROXY=localhost,mysql,rabbitmq
Maintenance window
The recipe of adt/docker-deployer runs pending
migrations in a maintenance window: it creates ~/project/maintenance on all servers, so that
the application holds no metadata locks of the tables being changed (DDL on a Galera cluster
conflicts with them). Handle it right after loadEnv(), before the DI container is created:
$configurator->loadEnv(__DIR__ . '/..'); $configurator->handleMaintenance();
- web:
503withRetry-After, a default page or your own (handleMaintenance($template)) - console: ends with exit code 0 (cron jobs skip a run), except the waiting commands
(default
['background-queue:consume'], second argument), which wait until the maintenance ends - supervisor would restart a consumer that exits in a loop
.env of the project:
# inside the containers; the deploy root ~/project is mounted at /var/www/html
MAINTENANCE_FILE=/var/www/html/maintenance
# commands of the deploy get 1 and skip the check; it must be listed (empty),
# otherwise `de` does not pass it into the container
MAINTENANCE_BYPASS=
Configurator::isMaintenance() tells whether the maintenance is on.
Preprod access
Preprod of a deploy (port 4434 of the edge proxy, nginx serves release/www by the header
X-Forwarded-Port: 4434) is open only to the IPs of PREPROD_IPS in .env - comma-separated
IPs or CIDRs, empty = open to everybody:
PREPROD_IPS=78.80.93.27, 203.0.113.0/24
$configurator->loadEnv(__DIR__ . '/..'); $configurator->handlePreprodAccess();
- others get
403before the application starts (the console is not affected); static files are served by nginx and stay public - private and loopback addresses always pass: the smoke check of the deploy (curl on the server, through the docker bridge) and the VPN
- the client is
X-Real-IPwhen the request comes from a private address (the edge proxy, which always overwrites the header), otherwiseREMOTE_ADDR- with or withoutreal_ipof nginx - an invalid entry matches nothing, a typo closes preprod instead of opening it
Debug mode on servers
The developer's own SSH key (ssh-ed25519) turns the debug mode on - nothing else is generated:
APP_DEVELOPERS(config/project/.env.common) is a JSON list of"<Slug>@ssh-ed25519 <base64>", the public SSH keys of the developers - nothing secret.- The cookie
app-debugcarries a token: an expiry (at most 366 days) and a host (*= every host) signed by the SSH key through ssh-agent (ssh-keygen -Y sign -n app-debug,ADT\DebugToken). The private key never leaves the developer's machine and never goes into a cookie. - The server turns the debug mode on only with the header
X-App-Debug-Allowed: 1, which the edge proxy (nginx-proxy of server-management-scripts) sends only to the IPs inNGINX_PROXY_DEBUG_IPSand always overwrites. Without the proxy (locally, directly) the cookie does nothing; locallyAPP_DEBUG=1.
With adt/make in any project:
make debug-token [DOMAIN=www.example.cz] [DAYS=365] # prints the cookie value
- New developer: add
"<Slug>@" + ~/.ssh/id_ed25519.pub(without the comment) toAPP_DEVELOPERS, deploy. - Leaving developer: remove the line, deploy. Tokens of the key stop working at once.
- A leaked cookie works only from the allowed IPs and until it expires.
Tracy bar with concurrent AJAX requests
In debug mode enableTracy() stores the deferred Tracy bar content in ADT\Tracy\LockFreeFileSession
instead of Tracy's FileSession. FileSession keeps the file of the tracy-session cookie
locked for the whole request, so concurrent AJAX requests of one browser (a page firing several
signals at once) run one after another. LockFreeFileSession locks the file only while reading
and writing and merges the changes of concurrent requests. A storage set by the project before
enableTracy() (Debugger::setSessionStorage()) is kept.
Tests
composer install
composer test