Class: Appconf

This class manages access to the configuration settings for all apps. In the usage example, both forms of each are equivalent, with the former being the recommended style for brevity.

Usage:

<?php

// get all settings for the myapp app
info (Appconf::myapp ());
info (Appconf::get ('myapp'));

// get the 'Admin' section of myapp's settings
info (Appconf::myapp ('Admin'));
info (Appconf::get ('myapp', 'Admin'));

// get the version of myapp
info (Appconf::myapp ('Admin', 'version'));
info (Appconf::get ('myapp', 'Admin', 'version'));

// update the version setting
Appconf::myapp ('Admin', 'version', '1.2.0');
Appconf::set ('myapp', 'Admin', 'version', '1.2.0');

// merge new settings for an app
$merged = Appconf::merge ('user', array (
    'User' => array (
        'logout_redirect' => '/'
        // etc
    )
));

?>

Properties

protected static $appconf = array ()

The settings array for all apps.

Methods

private static _conf ($app)

Get the configuration settings for an app. Returns an array of all settings.

public static __callStatic ($app, $args)

Get/set a configuration value for a given app. Use the app name as the method name, using the form:

Appconf::appname ($section = null, $setting = null, $new_value = null);

public static get ($app, $section, $setting)

Get a configuration value for an app. Can retrieve the entire app's settings, a section of the settings, or an individual value.

  • $app is the app name
  • $section is the section of the settings
  • $setting is the individiual setting name

If no $section is specified, the entire configuration for the app will be returned as an array.

If no $setting is specified, the section will be returned as an array.

public static set ($app, $section, $setting, $new_value)

Set a configuration value for an app. Note that this does not save the changes permanently, only for the current request.

  • $app is the app name
  • $section is the section of the settings
  • $setting is the individiual setting name
  • $new_value is the value to update the setting with

public static merge ($app, $new_values)

Get an updated configuration for an app based on its current settings and an array of new values. This new configuration can be saved to conf/app.APP_NAME.ELEFANT_ENV.php which will override the values in the original apps/APP_NAME/conf/config.php file. Note that the [Admin] section is omitted, since this should not be saved to custom configuration files.

  • $app is the app name
  • $new_values is the array of custom settings

Note: Use Ini::write() for writing the output to disk.

public static options ($basename = 'hooks', $hook = false)

Fetch all published hook handlers from a specific config file in across all apps. This may be a specific file, or a specific option list within the file.

Usage:

$payment_options = Appconf::options ('payments');
// array ('stripe/payment' => 'Stripe Payments')

$commands = Appconf::options ('cli', 'commands');
// array ('blog/publish-queue' => 'Publish scheduled...', ...etc...)