Componette

Componette

filips123

filips123 / ConfigWriter v2.0.3

Lightweight configuration writer for PHP

PHP Config Writer

Latest Stable Version Latest Untable Version Total Downloads License PHP

Linux Build Status Windows Build Status Code Coverage Code Quality

Lightweight configuration writer for PHP.

Installation

Requirements

PHP Config Writer requires PHP 5.5.9 or higher. Also, the config directory needs to be writable by web server in order to save config file.

Using Composer

The reccomended way to install ConfigWriter is with Composer, dependency manager for PHP.

You should just require filips123/config-writer in your project.

composer require filips123/config-writer:^2.0

You would only need to include autoloader and namespace in your script.

<?php

use ConfigWriter\Config;

require 'vendor/autoload.php';

$config = new Config;

Manually Installation

Alternatively, you could download files from GitHub and then manually include them in your script.

You whould need to include all files and namespace in your script.

<?php

use ConfigWriter\Config;

require 'src/Exceptions/UnsupportedFormatException.php';
require 'src/Exceptions/WriteException.php';
require 'src/ConfigInterface.php';
require 'src/AbstractConfig.php';
require 'src/Config.php';
require 'src/Record.php';
require 'src/Writers/WriterInterface.php';
require 'src/Writers/PhpWriter.php';

$config = new Config;

Usage

Making the configuration

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;
);

Adding records

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');

Adding sections

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');

Saving configuration

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.

Versioning

This project uses SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT license. See the LICENSE file for details.

  • v2.0.3 PHP Config Writer 2.0.3

    Fixed

    • Lock PHPUnit versions.
    • Update Travis CI PHP versions.
  • v2.0.2 ConfigWriter 2.0.2

    Fixed

    • Tests and assertions enhancement.
  • v2.0.1 ConfigWriter 2.0.1

    Fixed

    • Package name in README.
  • v2.0.0 ConfigWriter 2.0.0

    Added

    • Complete rewritten version.
    • Support for other writers.
    • Support for Composer and PSR-4.

    Fixed

    • Coding standards.
    • Tests.
  • v1.3.0 PHP config 1.3.0

    Added

    • Support to install with Composer.

    Fixed

    • Coding standards.
  • v1.2.0 PHP config 1.2.0

    Added

    • Some improvements.

    Fixed

    • Documentation.
    • Translations.
    • Other small fixes.
  • v1.1.0 PHP config 1.1.0

    Added

    • Support for getting status and errors.
  • v1.0.0 ConfigWriter 1.0.0

    Added

    • First release of ConfigWriter.
    • Support for writing config files in classic or class way.
bar-chart-fill

Statistics

download-cloud-fill
N/A
star-fill
1
bug-fill
0
flashlight-fill
4.2y
price-tag-2-line

Badges

Componette Componette felix@nette.org