joetjen.net
EN DE
← All libraries
PHP

php-cooper

Loads CASC config files into native PHP values — the PHP port of Cooper, the whole language, with .env layering and file caching.

Intention

The same documents should mean the same thing in a PHP application as in an Elixir one. Porting it is also what tested the specification: building this port turned up places where the Elixir original contradicted CASC.md, and they were fixed there. Where PHP has its own idiom — exceptions instead of result tuples, class names for modules — the port uses it, and lists each divergence.

Example
use JOetjen\Cooper\Cooper;

$config = Cooper::loadFile('config.casc', ['env' => ['DB_PASSWORD' => 'hunter2']]);

$config['database']['host'];                  // "db.eu-west.internal"
(string) $config['database']['password'];     // "[~~REDACTED~~]"
$config['database']['password']->reveal();    // "hunter2"
$config['database']['timeout']->nanoseconds;  // 500000000
Install
composer require joetjen/cooper
PHPConfigurationCASC