2017 © Pedro Peláez
 

library configurator

Generates config files from PHP, JSON and Yaml data files.

image

danack/configurator

Generates config files from PHP, JSON and Yaml data files.

  • Sunday, October 30, 2016
  • by Danack
  • Repository
  • 1 Watchers
  • 7 Stars
  • 1,334 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 18 Versions
  • 53 % Grown

The README.md

Configurator

A few simple tools to manage configuration data sanely. These tools are to hold environment data that can be shared without risk. They are not designed to hold 'secrets' e.g. api/oauth keys., (*1)

  • Config file generator, (*2)

  • Environment settings generator, (*3)

  • Convert PHP ini files to PHP-FPM format, (*4)

Philosophy

Environment variables need to be granular controls. Although they can be grouped together as "environments", they need to be configurable on a per-deploy basis without duplicating large blocks of information., (*5)

They also need to be stored alongside the application's code so that they can be maintained easily., (*6)

This library allows you to do these two things. All environment settings can be stored in a simple way, and then extracted and combined with arbitrary combinations. E.g. using 'centos,dev' as the environment setting uses all the 'centos' environment settings, with the 'dev' settings over-riding any duplicate settings., (*7)

Example usage for people who don't like reading instructions

If you install Configurator through Composer, the executable files will be in the vendor/bin directory and can be run with:, (*8)

# Generate nginx config file for the centos,dev environment
vendor/bin/configurate -p example/config.php example/config_template/nginx.conf.php autogen/nginx.conf "centos,dev"

# Generate a PHP file that contains a function which returns the current application env settings
vendor/bin/genenv -p example/config.php example/envRequired.php autogen/appEnv.php "centos,dev"

# Convert a PHP ini file to be in the PHP-FPM format
vendor/bin/fpmconv autogen/php.ini autogen/php.fpm.ini

Config file generator

This tool allows you to generate config files from PHP based templates and PHP data files that hold all of the settings for the different environments., (*9)

Source config template file:, (*10)

<?php

$config = <<< END

server {

    access_log  ${'nginx.log.directory'}/project.access.log requestTime;    
    error_log  ${'nginx.log.directory'}/project.error.log;
    root ${'project.root.directory'}/public;
}

END;

return $config;

Data file that holds data for arbitrary environments:, (*11)

<?php

$centos = [
    'nginx.log.directory' => '/var/log/nginx', 
    'project.root.directory' => '/home/project',
];

$windows = [
    'nginx.log.directory' => 'c:/nginx', 
    'project.root.directory' => 'c:/documents/project',
];

$john = [
    'project.root.directory' => '/home/workdir/project',
]

Running the command configurate data/nginx.conf.php var/generated/nginx.conf centos,john -p settings.php would generate the file:, (*12)

    access_log  /var/log/nginx/project.access.log requestTime;    
    error_log  /var/log/nginx/project.error.log;
    root /home/workdir/project/public;

Syntax

configurate [-p|--phpsettings="..."] [-j|--jssettings="..."] input output environment, (*13)

-p A comma separated list of PHP data files. Each need to return an array of data.
-j A comma separated list of JSON data files.
-y A comma separated list of YAML files.
input The input template file.
output The output file to write.
environment A comma separated list of environment settings to apply.

Generate environment settings

A tool that will parse the environment settings required by an application and the data files that hold the settings for all environments, and generate a file that contains a function which returns an array of what env settings are required by this application., (*14)

Given this file listing the environment settings required by an application:, (*15)

<?php

use ExampleApp\AppConfig;

$env = [
    AppConfig::CACHING_SETTING,
    AppConfig::SCRIPT_PACKING,
    AppConfig::FILE_STORAGE
];

return $env;

And a data file that holds all the data for the various environment settings:, (*16)

$dev = [
    AppConfig::SCRIPT_PACKING => true,
    AppConfig::CACHING_SETTING => 'caching.disable',
];

$live = [
    AppConfig::SCRIPT_PACKING => true,
    AppConfig::CACHING_SETTING => 'caching.time'
]; 

// Anyone doing UX testing needs to have the scripts packed together
// to avoid slow UI responses
$uxtesting = [AppConfig::SCRIPT_PACKING => true];

Running the command bin/genenv -p environment/config.php environment/envRequired.php env.php dev,uxtesting produces a file containing a single function which contains all the requested env settings:, (*17)

<?php

function getAppEnv() {
    static $env = [
        'caching.setting' => 'caching.disable',
        'script.packing' => 'true',
    ];

    return $env;
}

The keys are actual strings rather than the constants used in the application to allow the settings to be used outside of the application., (*18)

Syntax

genenv [-p|--phpsettings="..."] [-j|--jssettings="..."] input output environment, (*19)

-p A comma separated list of PHP data files. Each need to return an array of data.
-j A comma separated list of JSON data files.
-y A comma separated list of YAML files.
input The input template file.
output The output file to write.
environment A comma separated list of environment settings to apply.

Convert PHP ini files to PHP-FPM format

Because of reasons, PHP-FPM doesn't use the standard PHP in file format when including ini files in a pool in the PHP-FPM conf file. This aspect of the Configurator converts PHP style ini files to the format PHP-FPM expects:, (*20)

Input ini file:, (*21)

extension=imagick.so
default_charset = "utf-8";
post_max_size = 10M

Running the command php bin/fpmconv example.php.ini example.phpfpm.ini, (*22)

will generate this PHP-FPM ini file:, (*23)

php_admin_value[extension] = "imagick.so"
php_admin_value[default_charset] = "utf-8"
php_admin_value[post_max_size] = "10M"

The Versions

30/10 2016

dev-master

9999999-dev

Generates config files from PHP, JSON and Yaml data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

18/03 2016

1.0.0

1.0.0.0

Generates config files from PHP, JSON and Yaml data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

26/01 2016

0.4.0

0.4.0.0

Generates config files from PHP, JSON and Yaml data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

21/01 2016

0.3.2

0.3.2.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

21/01 2016

0.3.1

0.3.1.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

10/10 2015

0.3.0

0.3.0.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

06/10 2015

0.2.9

0.2.9.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php configuration config utf-8 environment tool

15/09 2015

0.2.8

0.2.8.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

24/08 2015

0.2.7

0.2.7.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

19/08 2015

0.2.6

0.2.6.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

06/07 2015

0.2.5

0.2.5.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

18/05 2015

0.2.4

0.2.4.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

27/02 2015

0.2.3

0.2.3.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

The Development Requires

php config utf-8 tool

04/02 2015

0.2.2

0.2.2.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

php config utf-8 tool

04/02 2015

0.2.1

0.2.1.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

php config utf-8 tool

04/02 2015

0.2.0

0.2.0.0

Generates config files from PHP based config files and PHP and JSON data files.

  Sources   Download

MIT

The Requires

 

php config utf-8 tool

12/04 2014

0.1.1

0.1.1.0

Generates config files from PHP based templates and PHP style config files..

  Sources   Download

MIT

php config utf-8 tool

06/06 2013

0.1.0

0.1.0.0

Generates config files from PHP based templates and PHP style config files..

  Sources   Download

MIT

php config utf-8 tool