-
-
Notifications
You must be signed in to change notification settings - Fork 1
Usage
Configuration making is possible using ConfigWriter\Config class.
$config = new Config;It accepts two parameters, data and comment, and both are optional. Data parameter contains pre-set data for configuration and comment contains additional comment (or code) on top of the configuration file.
$config = new Config(
[
'username' => 'user',
'password' => 'pass',
],
<<<EOD
/**
* The configuration file.
*
* It contains configuration data.
*/
EOD;
);Records can be added using ConfigWriter\Config::addRecord() method.
$config->addRecord('application', 'ConfigWriter');They can also have comments, which will be generated in documentation.
$config->addRecord('application', 'ConfigWriter', 'Application name');Sections visually and functionally separate multiple records. They can be added using ConfigWriter\Config::addSection() method.
$database = $config->addSection('database', [], 'Database settings');
$database->addRecord('host', 'localhost', 'Database host');
$database->addRecord('port', '3306', 'Database port');They can also have pre-set data using second parameter.
$config->addSection(
'database',
[
'host' => 'localhost',
'port' => '3306',
],
'Database settings');You can save configuration using ConfigWriter\Config::toString() or ConfigWriter\Config::toFile().
When saving to string, configuration writer is required, and when saving to file, writer will be automatically determined.
$config->toString(new ConfigWriter\Writers\PhpWriter);
$config->toFile('config.php');Writers can also have specific options for writing.
$config->toFile('config.php', new ConfigWriter\Writers\PhpWriter, ['indentation' => ' ']);The only supported writer is for PHP array, but more writers will be added later.