joetjen.net
EN DE
← All libraries
PHP

php-cooper-config

Loads an application’s CASC configuration once, at startup, as plain PHP values, with a per-application secrets policy and a compiled, opcache-friendly cache between requests.

Intention

Configuration arrives; it is not asked for. A broken document stops the program at its first line instead of at whichever request first reads a broken setting. PHP being shared-nothing, “once at startup” is once per request under PHP-FPM, and the compiled cache is what makes that cheap. It is the PHP counterpart of cooper_config: the same document, the same conversion rules.

Example
use JOetjen\CooperConfig\Config;

Config::load();   // the first thing the front controller does

Config::get('http.port');              // 8080
Config::require('database.password');  // "hunter2" -- revealed by default
Config::get('database.timeout');       // 5000 -- milliseconds
cooper_config('cache.ttl', 60);        // 60 -- not configured, so the default
Install
composer require joetjen/cooper-config
PHPConfiguration