Skip to content

Storing configuration

pago edited this page Apr 15, 2011 · 2 revisions

pantr bundles the really nice sfYaml library and makes it available in any pantrfile. In order to help you with your configuration needs, pantr provides a config cascade. Whenever you use the pantr::loadProperties function to load a config file, pantr will try to load a file with the same name in ~/.pantr (~/Library/Application Support/pantr on Mac unless ~/.pantr exists) first.
You can change the directory by setting the PANTR_HOME environment variable.
If you want to disable the cascade you can pass in “false” as the second value of pantr::loadProperties (the first argument being the name of the file you’d like to load).

After you have loaded a configuration file, you can access its data using the property function.

property('name')

Since yaml files are usually deeply nested trees pantr provides a special syntax to help you get the property you’d like to get a little bit easier. If the property name contains a “:” (colon), pantr will traverse the tree until it reaches the specified property or ends up with a dead end (in that case null is returned).

~/.pantr/pantr.yaml

pear:
  local:
    server: pear.localhost.lo

Usage in pantrfile:

property('pear:local:server');

Note that the ~/.pantr/pantr.yaml file is always loaded when a pantrfile is executed.

To set a property in your pantrfile you can provide its value as the second parameter to the
property function:

property('foo', 'bar');

Note that you cannot set a nested property using the colon syntax.

Clone this wiki locally