Configuration

Configuration is all native PHP code using array syntax. The configuration array is returned at the bottom of the main configuration file so it can be correctly scoped and stored in a variable.

Shortened example configuration file:

File: app/config/app.php


            
// Configuration $cfg = array(); // ... (snip) ... // Debug? $cfg['debug'] = false; // In Development Mode? $cfg['mode']['development'] = true; // ... (snip) ... // Locale Settings $cfg['i18n'] = array( 'charset' => 'UTF-8', 'language' => 'en_US', 'timezone' => 'America/Chicago' ); // Return config array at the end return $cfg;

          
A configuration array is built and then explicitly returned at the end of the file. This allows Alloy to reliably keep configuration settings in a known variable reference to set them for the application.

Config Overrides by Hostname

In Alloy, it is possible to provide configuration overrides for different envirornments by hostname.

The main config file is found here:
app/config/app.php

This file can be overridden by a custom hostname-based configuration:
app/config//app.php

The hostname is determined by a php_uname('n') call in the bootstrap file.

Retrieving Config Values (Getter)

Configuration values can be retrieved directly from the Kernel by calling the config method. Nested configuration values as resolved using a dot syntax.


            
// "America/Chicago" $timezone = $kernel->config('i18n.timezone');

          

If you are unsure if a config value will be present, you can supply a default as the second parameter.


            
// If 'database.master.host' key not found, 'localhost' will be returned $dbHost = $kernel->config('database.master.host', 'localhost');

          

Setting Config Values (Setter)

The same config method can be used to set config values if the first parameter passed is an array. If the config keys passed in the array are already present, they will be overwritten with the new values passed in.


            
// Set timezone to "America/Sao_Paulo" $timezone = $kernel->config(array( 'i18n' => array( 'timezone' => 'America/Sao_Paulo' ) ));

          

Related Links