\ConfigForge

ConfigForge class for managing configuration files

This class provides functionality to load, edit, and save configuration files
based on a specification file.
available types: TEXT, CHECKBOX, RADIO, SELECT, TRIGGER, PASSWORD, SLIDER
available patterns for TEXT type:
- alpha: only Latin letters [a-zA-Z] (e.g., "abcDEF")
- alphanumeric: only Latin letters and numbers [a-zA-Z0-9] (e.g., "abc123")
- digits: only digits [0-9] (e.g., "12345")
- email: valid email address format (e.g., "user@domain.com")
- finance: decimal numbers with optional decimal point (e.g., "123.45", "100", "0.99")
- float: floating point numbers (e.g., "123.45", "0.001")
- fullpath: absolute Unix-style paths starting with / (e.g., "/var/www/html")
- geo: geographic coordinates (e.g., "40.7143528,-74.0059731")
- ip: IPv4 address format (e.g., "192.168.1.1")
- login: username format with letters, numbers and underscore (e.g., "user_123")
- mac: MAC address format with : or - separator (e.g., "00:1A:2B:3C:4D:5E")
- mobile: phone number with optional country code (e.g., "+380501234567")
- net-cidr: network CIDR notation, mask can't be /31 (e.g., "192.168.1.0/24")
- filepath: relative or absolute Unix-style paths (e.g., "dir/file.txt", "/etc/config")
- dirpath: relative or absolute Unix-style directories paths (e.g., "dir/", "/etc/")
- pathorurl: URLs with optional ports or paths (e.g., "http://example.com:8080", "some/dir/")
- sigint: signed integers (e.g., "-123", "456")
- url: HTTP/HTTPS URLs with optional port numbers (e.g., "http://example.com:8080")

Specification file example:

[sectionname]
LABEL="Option label"
OPTION=SOME_OPTION
TYPE=CHECKBOX
DEFAULT=0

[sectionname2]
LABEL="Your sex?"
OPTION=SEX
TYPE=SELECT
VALUES="male,female,unknown"
DEFAULT="unknown"
SAVEFILTER="gigasafe"

[sectionname3]
LABEL="Option label 2"
OPTION=ANOTHER_OPTION
TYPE=TEXT
PATTERN="mac"
VALIDATOR="IsMacValid"
ONINVALID="This mac address is invalid"
DEFAULT="14:88:92:94:94:61"

[sectionname4]
LABEL="Volume level"
OPTION=VOLUME
VALUES="0..100"
TYPE=SLIDER
DEFAULT=50


class usage example:
$configPath = 'config/test.ini';
$specPath = 'config/test.spec';
$forge = new ConfigForge($configPath, $specPath);
$processResult = $forge->process();
if (!empty($processResult)) {
show_error($processResult);
} elseif (ubRouting::post(ConfigForge::FORM_SUBMIT_KEY)==$forge->getInstanceId()) {
ubRouting::nav('?module=testing');
}

show_window(__('Config Forge'), $forge->renderEditor());