PHPackages                             apinstein/config\_magic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. apinstein/config\_magic

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

apinstein/config\_magic
=======================

Configuration management system for arbitrary

v1.0.4(12y ago)412.6k1[2 issues](https://github.com/apinstein/config-magic/issues)MITPHPPHP &gt;=5.2.0

Since Jan 22Pushed 7y ago1 watchersCompare

[ Source](https://github.com/apinstein/config-magic)[ Packagist](https://packagist.org/packages/apinstein/config_magic)[ Docs](http://github.com/apinstein/config-magic)[ RSS](/packages/apinstein-config-magic/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

ConfigMagic
===========

[](#configmagic)

A simple organizational tool to help you manage config files for your web app.

INSTALLATION
------------

[](#installation)

```
$ composer global require apinstein/config_magic
```

HOW IT WORKS
------------

[](#how-it-works)

A typical web app has 1 or more config files. For instance, your app might have the following files: httpd.conf (apache config) webapp.conf (framework config) sh.conf (shell script config)

A typical web app is also run on more than one server. For instance: dev-alan dev-jason staging production

Configuring your web app to run on a new envirionment can quickly become a painful process as you have to remember to edit multiple files with correct information. In my experience, a lot of time is wasted trying to: - Bootstrap the new environment one config file at a time - Remember all of the different places and values that need to be configued - Messing with regex replacements to try to batch-replace things listed repetitively

ConfigMagic solves these problems by letting you quickly and easily set up template files for each config file. Your template file can contain default data for each variable substitution used by your configs. You then need only set up a profile.ini for each machine profile and declare any non-default data you need to use. ConfigMagic then writes out all config files for a given profile.

ConfigMagic comes with a command-line utility "cfg" that lets you quickly manage this process.

EXAMPLE
-------

[](#example)

Initialize ConfigMagic for this project.

```
$ cfg -i
```

Set up an example config file

```
$ echo "myProfile = ##PROFILE##" > config/templates/example.conf
$ echo "myVar = ##my.var##" >> config/templates/example.conf
```

Set up an empty profile

```
$ echo "my.var = 10" > config/profiles/dev.ini
```

Build all config files for the "dev" profile

```
$ cfg dev
```

Check

```
$ cat config/example.conf
```

Output:

```
myProfile = dev
myVar = 10

```

VARIABLE SUBSTITUION
--------------------

[](#variable-substituion)

Variables in the template files take the form of:

`##my.var##`

And will be replace by the corresponding ini file variable:

`my.var`

Variables in the profile.ini file override the default values set in the config.ini file.

Variables can also use variable substituion on variables previously defined (ie higher in the file).

a = foo b = ##a##-bar # b = foo-bar

The following additional variables are automatically defined:

`##CONFIG##` =&gt; the current config name `##PROFILE##` =&gt; the current profile name `##CONFIG_DIR##` =&gt; the absolute path to the config dir `##OUTPUT_DIR##` =&gt; the absolute path to the output dir `##TEMPLATES_DIR##` =&gt; the absolute path to the config/templates dir

Any variable substitution in the template file that isn't defined in any ini file will be skipped and a warning will print out.

DYNAMIC TEMPLATES
-----------------

[](#dynamic-templates)

All templates are treated as PHP code, which means that you can use normal PHP syntax to dynamically generate config files based on profile data.

All variables available in normal variable substition (in form of ##varname##) are available in the template, via the $profileData variable. For instance:

```
