Configuration
Configuration settings are stored at the framework's configuration file. These settings can be changed, for instance, to make the framework use a different cache engine, storage locations and other.
Configuration File Location
Configuration file "app.php" is located at folder "app/config".Add Custom Settings
Custom configuration settings can be added by appending them to the configuration file's array.
return [ // ... CONFIGURATION SETTINGS // "my_setting" would be a custom setting added to the configuration file 'my_setting' => [ 'setting_a' => 123456, 'setting_b' => 'example string', ], ];
Custom settings can only be accessed through the Main Class.
// Get all settings set at "my_setting" $mysetting = get_bridge( 'MyNamespace' )->config->get('my_setting'); // Only get "setting_a" from "my_setting". $setting_a = get_bridge( 'MyNamespace' )->config->get('my_setting.setting_a');
In the example above, custom settings are accessed through the project's Main Class (using the get_bridge()
global function).
Add Custom Configuration File
Additional configuration files with custom settings can be created.
The example below displays the content of a custom configuration file located at app/Config/custom.php
:
return [ 'api' => [ 'api_key' => 123456, 'api_secret' => 'example string', ], ];
Custom configuration file content can be loaded using the Main class:
/** * Load file at `app/Config/custom.php` * @return WPMVC\Config */ $custom_config= get_bridge( 'MyNamespace' )->load_config( 'custom' ); // Read data $api_key = $custom_config->get( 'api.api_key' );
In the example above, the custom configuration file is loaded into a new variable of WPMVC\Config, which is later used to read the settings inside.
Environment definitions
Configuration settings can be overwritten by defining them inside the wp-config.php
configuration file. This will help define different environment settings without changing the actual application configuration file.
For example, if a configuration key is api.api_key
it can be overwritten inside wp-config.php
like this:
define( 'api.api_key', 'My overwritten value' );