PHP Classes

PHP Configuration Writer: Generate configuration files as PHP scripts

Recommend this page to a friend!
  Info   View files Documentation   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 101 All time: 9,780 This week: 206Up
Version License PHP version Categories
config-writer 2MIT/X Consortium ...5PHP 5, Code Generation, Configuration
Description 

Author

This package can generate configuration files as PHP scripts.

It takes an associative array as initial values for configuration that can be changed dynamically.

The configuration can be changed by adding individual values or whole new sections of values.

The package can generate a PHP script as output to be used by applications that can include the script to use the configuration values.

The package can also take a string as parameter that defines heading comments of the output PHP script configuration file.

Picture of Filip Štamcar
  Performance   Level  
Name: Filip Štamcar <contact>
Classes: 3 packages by
Country: Slovenia Slovenia
Age: ???
All time rank: 408811 in Slovenia Slovenia
Week rank: 286 Up1 in Slovenia Slovenia Up
Innovation award
Innovation award
Nominee: 1x

Documentation

PHP Config Writer

[![Latest Stable Version][icon-stable-version]][link-packagist] [![Latest Untable Version][icon-unstable-version]][link-packagist] [![Total Downloads][icon-downloads]][link-packagist] [![License][icon-license]][link-license] [![PHP][icon-php]][link-php]

[![Linux Build Status][icon-travis]][link-travis] [![Windows Build Status][icon-appveyor]][link-appveyor] [![Code Coverage][icon-coverage]][link-coverage] [![Code Quality][icon-quality]][link-quality]

Lightweight configuration writer for PHP.

Installation

Requirements

MonologPHPMailer requires [PHP][link-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][link-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][link-semver] for versioning. For the versions available, see the [tags on this repository][link-tags].

License

This project is licensed under the MIT license. See the [LICENSE][link-license-file] file for details.

[icon-stable-version]: https://img.shields.io/packagist/v/filips123/config-writer.svg?style=flat-square&label=Latest+Stable+Version [icon-unstable-version]: https://img.shields.io/packagist/vpre/filips123/config-writer.svg?style=flat-square&label=Latest+Unstable+Version [icon-downloads]: https://img.shields.io/packagist/dt/filips123/config-writer.svg?style=flat-square&label=Downloads [icon-license]: https://img.shields.io/packagist/l/filips123/config-writer.svg?style=flat-square&label=License [icon-php]: https://img.shields.io/packagist/php-v/filips123/config-writer.svg?style=flat-square&label=PHP [icon-travis]: https://img.shields.io/travis/com/filips123/ConfigWriter.svg?style=flat-square&label=Linux+Build+Status [icon-appveyor]: https://img.shields.io/appveyor/ci/filips123/ConfigWriter.svg?style=flat-square&label=Windows+Build+Status [icon-coverage]: https://img.shields.io/scrutinizer/coverage/g/filips123/ConfigWriter.svg?style=flat-square&label=Code+Coverage [icon-quality]: https://img.shields.io/scrutinizer/g/filips123/ConfigWriter.svg?style=flat-square&label=Code+Quality

[link-packagist]: https://packagist.org/packages/filips123/config-writer/ [link-license]: https://choosealicense.com/licenses/mit/ [link-php]: https://php.net/ [link-composer]: https://getcomposer.org/ [link-travis]: https://travis-ci.com/filips123/ConfigWriter/ [link-appveyor]: https://ci.appveyor.com/project/filips123/configwriter/ [link-coverage]: https://scrutinizer-ci.com/g/filips123/ConfigWriter/code-structure/ [link-quality]: https://scrutinizer-ci.com/g/filips123/ConfigWriter/ [link-semver]: https://semver.org/ [link-tags]: https://github.com/filips123/ConfigWriter/tags/ [link-license-file]: https://github.com/filips123/ConfigWriter/blob/master/LICENSE


  Files folder image Files  
File Role Description
Files folder imagesrc (4 files, 2 directories)
Files folder imagetests (3 files, 1 directory)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml.dist Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
Files folder imageExceptions (2 files)
Files folder imageWriters (2 files)
  Plain text file AbstractConfig.php Class Class source
  Plain text file Config.php Class Class source
  Plain text file ConfigInterface.php Class Class source
  Plain text file Record.php Class Class source

  Files folder image Files  /  src  /  Exceptions  
File Role Description
  Plain text file UnsupportedFormatException.php Class Class source
  Plain text file WriteException.php Class Class source

  Files folder image Files  /  src  /  Writers  
File Role Description
  Plain text file PhpWriter.php Class Class source
  Plain text file WriterInterface.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageWriters (1 file)
  Plain text file AbstractConfigTest.php Class Class source
  Plain text file ConfigTest.php Class Class source
  Plain text file RecordTest.php Class Class source

  Files folder image Files  /  tests  /  Writers  
File Role Description
  Plain text file PhpWriterTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:101
This week:0
All time:9,780
This week:206Up