The main installation configuration parameters are stored in the following locations:
Type | Location |
---|---|
Global | includes/OSC/Conf/global.php |
Per-Site | includes/OSC/Sites/SITE/site_conf.php |
The global configuration file and all site configuration files are automatically loaded into their own groups when the framework is initialized. The global configuration file is loaded into a 'global' group, and the site configuration files are loaded into their own Site group (eg, 'Admin', and 'Shop').
Reading a configuration value is first attempted at the Site level, and if the configuration key does not exist, the global value is returned. A Site level configuration parameter has priority over a global level parameter if a global level configuration parameter is also defined.
It's possible to create custom configuration files that have priority over the values from the core configuration files. Custom configuration files can be stored in the following locations:
Type | Location |
---|---|
Global | includes/OSC/Custom/Conf/global.php |
Per-Site | includes/OSC/Custom/Sites/SITE/site_conf.php |
The format of the configuration parameters are stored in a "ini" style format in a PHP file that is assigned to a $ini PHP variable. This style of configuration was chosen over a plain text .ini file to prevent configuration parameters being read in cases of the configuration files being publicly accessible through the web server.
An example format for the global configuration file is:
<?php
$ini = <<<EOD
db_server = "localhost"
db_server_username = "dbuser"
db_server_password = "dbpass"
db_database = "oscommerce"
db_table_prefix = "osc_"
store_sessions = "MySQL"
time_zone = "Europe/Berlin"
EOD;
An example of a Site configuration file is:
<?php
$ini = <<<EOD
dir_root = "/www/html/"
http_server = "https://demo.oscommerce.shop"
http_path = "/"
http_images_path = "images/"
http_cookie_domain = ".oscommerce.shop"
http_cookie_path = "/"
EOD;
External configuration files can be loaded using the following code:
use OSC\OM\OSCOM;
OSCOM::loadConfigFile($path_of_file, 'ext_group');
This would load the configuration parameters of $path_of_file to the 'ext_group' configuration group.
It is important that the ini format is stored as a string to the $ini PHP variable otherwise the configuration parameters can not be parsed.
Configuration parameters can be retrieved using OSCOM::getConfig():
use OSC\OM\OSCOM;
$value = OSCOM::getConfig('cfg_name');
In this example, the cfg_name configuration parameter from the current Site group is returned. If the current Site group does not contain the configuration parameter, the global group value is returned.
It's possible to define which group the configuration parameter should be loaded from by defining the group name:
use OSC\OM\OSCOM;
$value = OSCOM::getConfig('cfg_name', 'ext_group');
This would load the cfg_name configuration parameter from the ext_group group.
The following can be used to first see if a configuration parameter exists:
use OSC\OM\OSCOM;
if (OSCOM::configExists('cfg_name')) {
....
}
This will check if cfg_name exists in the current Site group or the global group.
Checking to see if a configuration parameter exists in a specific group is performed as follows:
use OSC\OM\OSCOM;
if (OSCOM::configExists('cfg_name', 'ext_group')) {
....
}
Please note that if the configuration parameter does not exist in the specified group, a check is also performed in the global group.
Runtime configuration parameters can be set as follows:
use OSC\OM\OSCOM;
$value = true;
OSCOM::setConfig('is_true', $value, 'ext_group');
If no group is specified in the third parameter, the configuration parameter would be set in the global group.
This function does not save the configuration parameter to the configuration file - it only sets a runtime configuration parameter value.