-
-
Notifications
You must be signed in to change notification settings - Fork 1
Home
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:
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__);The Config object supports dot notation and typed getters.
$host = $config->getString("database.host");
$port = $config->getInt("database.port");
$debug = $config->getBool("app.debug");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");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.
PHP.GT/Config is a separately maintained component of PHP.GT/WebEngine.