Skip to content
Muhammet Şafak edited this page May 24, 2026 · 2 revisions

InitPHP ParameterBag — Wiki

Welcome to the official documentation for initphp/parameterbag — a small, dependency-free container that gives PHP applications a uniform, default-aware API over both flat key/value data and nested (dotted-path) structures.

The package ships two types:

Type Purpose
ParameterBag The default concrete implementation; open for extension.
ParameterBagInterface The contract — depend on this in your services.

Both types satisfy PHP's standard collection contracts — ArrayAccess, Countable, IteratorAggregate — so the bag drops into any code that consumes those interfaces.

composer require initphp/parameterbag
use InitPHP\ParameterBag\ParameterBag;

$config = new ParameterBag([
    'app' => ['name' => 'demo', 'debug' => false],
    'db'  => ['dsn'  => 'mysql:host=localhost', 'user' => 'root'],
]);

$config->get('app.name');                 // 'demo'
$config->get('db.charset', 'utf8mb4');    // 'utf8mb4' (default)
$config->set('app.debug', true)->merge(['db' => ['pass' => 'secret']]);

Start here

At a glance — feature matrix

Capability Flat mode (isMulti = false) Multi mode (isMulti = true)
get / set / has / remove of top-level keys
Dotted-path access (db.user) ❌ (dot is part of the key)
Configurable separator n/a ✅ ('.' default)
Case-insensitive keys (opt-in)
Merge strategy array_merge (shallow) array_replace_recursive (deep)
ArrayAccess $bag['x'] ✅ (path supported)
Countable / IteratorAggregate top-level entries only top-level entries only
Strict option validation (unknown keys throw)
Null values distinguishable from missing

Package metadata

If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.

Clone this wiki locally