Git Product home page Git Product logo

config-9's Introduction

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.

Also provides functionality for generating ini files from the CLI.

Documentation: https://php.gt/docs/config


Build status Code quality Code coverage Current version PHP.Gt/Config documentation

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.

nginx.conf:

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

config.ini:

[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:

[database]
host = localhost

example.php:

// 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.

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.

config-9's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar g105b avatar peter279k avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.