webCOMAND

loader::load_config()

Return an associative array from a configuration file that contains a PHP associative array that looks like the following.

// associative array to be loaded by load_config()
$config = [
    'key 1' => 'value 1',
    'key 2' => 'value 2'
];

The configuration file is loaded based on an identifier and package.  The API will search for the configuration file with a name based on the identifier (followed by .php) in the config folder of the package, in all the places the auto-loader is configured to search for the package.  The associative arrays in all found configuration files will be merged into a single associative array.  Initially loaded values will be overridden by subsequent loaded values based on the package path load order (see add_package_path() for details).

The returned value is cached to improve performance of subsequent requests for the same identifier and package.

Prototype

array load_config(string $identifier, string $package, bool $force = FALSE)

Parameters

  • identifier - string that contains the name of the configuration file, minus the ".php" extension at the end.
  • package - string that contains the name of the package with the configuration file.  For example, "com_example_app".
  • force - optional parameter that can be used to force the configuration(s) to be reloaded, instead of using the cached result of a previous call for the same identifier and package.

Return

Returns the associative array defined in the configuration file as $config.  If the configuration file is not found or contains an error, FALSE is returned.

Example

require_once('path/to/comand.php');

// add new base path to be searched first
\io_comand\loader::add_base_path('new/base/path');

// try to load config from config folder under new/base/path
// and then the default paths, in that order
$my_config = \io_comand\loader::load_config('my_config', 'com_example');

echo($my_config['key'] . "\n");