Configuration - ApinePHP/legacy-framework GitHub Wiki

The Configuration utility allow to save configuration information to external files. It automates the validation and the writing process which makes it a great alternative to manual parsing and writing of configuration files.

The configuration utility support the INI file format with sections to store data.

Usage

To access the configuration utility, you must import the Config class from the Core module.

use Apine\Core\Config;

The constructor of the class requires one argument which is the path to the configuration file.The constructor of the class requires one argument which is the path to the configuration file.

$config = new Config(‘config.ini’);

To read a value from the config, use the get method.

$value = $config->get(‘application’, ‘title’);

To save a value to the config, use the set method.

$config->set(‘application’, ‘title’, ‘APIne Example’);

Methods

__construct (string $a_path) : Config

Create a Config instance representing a configuration file.

The parameter is a string representing the path to the config file. The path can either be absolute or relative to the location of the root of the project. It throws an exception if the file is not found.

get (string $prefix [, string $key]) : string

Fetch a string from the configuration.

Parameters are strings representing the section (prefix) where the variable (key) is located. It returns a string representing the value on success. It returns null when the variable is not found.

get_config () : array

Return an array of all the configurations

set (string $prefix, string $key, string $value)

Write or update a configuration string.

The first two parameters are strings representing the section (prefix) where the variable (key) is located. The third is the string to be saved. The changes are directly pushed to the configuration file.