zendframework/zend-pimple-config
zendframework/zend-pimple-config integrates Zend Framework configuration with the Pimple dependency injection container. It lets you load and merge config data and wire services/parameters into a Pimple container for cleaner, centralized DI setup.
Start by installing the package via Composer: composer require zendframework/zend-pimple-config. This package assumes you already use Pimple (v3+), so ensure it’s present. The core class is Zend\PimpleConfig\Config, which loads and aggregates configuration. The first use case is typically bootstrapping a lightweight app: create a config.php (or .config directory with global.php, local.php, etc.) that returns an array or ArrayObject (Zend-style), then feed it into Config. Example:
use Zend\PimpleConfig\Config;
use Pimple\Container;
$config = new Config([
'config_path' => __DIR__ . '/config',
]);
$container = new Container();
$config->populate($container);
The populate() method merges all discovered config files and injects them into the container as parameters (e.g., db.hostname becomes $container['db']['hostname'] or via offsetGet()), and can also register services if factories or invokables keys are present.
Use layered configuration: define global.php (default settings) and local.php (local overrides, ignored in VCS) in config/. The Config object automatically loads both, with later files overriding earlier ones. For environment-specific behavior (e.g., dev vs prod), use config/config.php that returns ['environment' => 'prod'], then conditionally include prod.config.php in your config path.
Key patterns include:
invokables (class → service name) or factories (callable + dependencies), avoiding imperative container setup.For microservices, create a single config.php that returns a nested array (db, cache, services, etc.), then call populate() once on container init. Keep config files as pure PHP arrays for speed and clarity — no YAML/JSON needed.
$container['db']['driver'] fails if db isn’t defined). Always pre-initialize parent keys ('db' => ['driver' => 'mysql']) in config.%env(VAR)%. Do pre-processing manually or use $_ENV in config files.Config::getMergedConfig() after population to dump final config for debugging or caching.new Config(['config_path' => $path, 'config_cache_enabled' => true]) if you add caching manually (note: package itself has no cache built-in — just aggregates sources at runtime).Config to add custom processing (e.g., JSON schema validation, nested secrets decryption).container-interop + symfony/config for active support.How can I help you explore Laravel packages today?