2017 © Pedro Peláez
 

library config

Load configuration from ini files or environment variables.

image

phpgt/config

Load configuration from ini files or environment variables.

  • Monday, July 30, 2018
  • by g105b
  • Repository
  • 1 Watchers
  • 0 Stars
  • 161 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 455 % Grown

The README.md

Manage configuration with ini files and environment variables.

Manage your project configuration by defining defaults, that can be overridden by ini files and environment variables., (*1)

Also provides functionality for generating ini files from the CLI., (*2)

Documentation: https://php.gt/docs/config, (*3)


Build status Code quality Code coverage Current version PHP.Gt/Config documentation , (*4)

Example usage - loading project configuration:

A project's configuration can be split across multiple files. The following example shows how a secret can be supplied through the environment, which is used to override the default value defined within config.ini, and also shows how other named config files can be used., (*5)

nginx.conf:, (*6)

location ~ \.php$ {
    fastcgi_pass    unix:/var/run/php/php7.1-fpm.sock;
    fastcgi_param   database_password   super-secret-passw0rd;
    include     fastcgi_params;
}

config.ini:, (*7)

[app]
namespace = MyApp
debug = true
logging = verbose

[database]
host = db.example.com
schema = local_shop
username = admin
password = admin_pass

[shopapi]
key = jungfnyyguvffubhgvat
secret = guvfvfnybpnyfubcgurerfabguvatsbelbhurer

config.dev.ini:, (*8)

[database]
host = localhost

example.php:, (*9)

// Load config.ini
$config = new Config("/path/to/project");

// Note that the database password is overriden in the environment (from nginx)
// and the host is overridden by the development ini file.
echo $config->get("database.host");     // localhost
echo $config->get("database.port");     // 6612
echo $config->get("database.password");     // super-secret-passw0rd

Example usage - generating configuration files:

Sometimes it's useful to generate config files on-the-fly, such as from Continuous Integration scripts. Below shows a quick example of how to generate a config.deploy.ini file with a few key-values that will override the default., (*10)

vendor/bin/config-generate deploy "shopapi.key=test-api-key" "database.schema=local_shop_$BRANCH_NAME"

The above command will create a config.deploy.ini file (note the first argument of "deploy") and provide overrides for two ini keys using dot notation. Note that because this command will be run within a continuous integration setting, we are expecting there to be a $BRANCH_NAME variable set for us, allowing us to use a schema name containing the current branch., (*11)

The Versions

30/07 2018

dev-master

9999999-dev

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

15/06 2018

v0.3.2

0.3.2.0

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2018

v0.3.1

0.3.1.0

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2018

dev-18-writer

dev-18-writer

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

07/06 2018

v0.3.0

0.3.0.0

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/06 2018

dev-16-overrides

dev-16-overrides

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

 

The Development Requires

31/05 2018

v0.2.0

0.2.0.0

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

30/05 2018

v0.1.0

0.1.0.0

Load configuration from ini files or environment variables.

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

16/02 2016

v0.0.1

0.0.1.0

Load environment variables

  Sources   Download

MIT

The Requires

 

The Development Requires