Skip to content
Greg Bowler edited this page Mar 16, 2026 · 11 revisions

PHP.GT/Config parses INI files for managing application configuration, allowing you to override files and environment variables. It keeps configuration grouped into named sections, gives you typed access to values, and provides tools for loading and writing config from both PHP code and the command line.

Storing application configuration in INI files allows us to keep default values in version control, layer environment-specific overrides on top, and encapsulate sections of configuration, passing data to the parts of the application that need it.

The library has four main areas:

1. Load configuration from files

The ConfigFactory looks for a project's config.ini files, parses them, and combines them in the correct order.

use Gt\Config\ConfigFactory;

$config = ConfigFactory::createForProject(__DIR__);

2. Read values safely

The Config object supports dot notation and typed getters.

$host = $config->getString("database.host");
$port = $config->getInt("database.port");
$debug = $config->getBool("app.debug");

3. Work with sections

Configuration can be split into logical groups, and an individual ConfigSection can be passed to a service that only needs one area of configuration.

$dbConfig = $config->getSection("database");
$password = $dbConfig?->getString("password");

4. Generate or write config files

Deployment config can be created from CI scripts using the bundled config-generate command, or by writing a Config object back to disk in PHP.

vendor/bin/config-generate staging "database.host=staging-db.internal"

To begin, let us look at some Example config files.