Feature: PHP configuration support
Problem Statement
Currently, Hazaar\Application\Config
supports configuration using formats such as JSON, INI, or YAML. However, it does not support native PHP files, which limits flexibility for developers who prefer using executable logic within configuration files or want to maintain consistency with legacy applications.
Who will benefit?
- Developers migrating from legacy PHP applications using array-based configuration files.
- Developers wanting to define dynamic configuration values using PHP.
- Projects requiring complex configuration logic not easily expressed in static formats.
Benefits and risks
Benefits:
- Enables executable and dynamic configuration logic.
- Reduces duplication by allowing use of shared constants or functions in configuration.
- Eases migration from projects already using PHP-based configuration.
Risks:
- Allows arbitrary code execution, which may introduce security concerns if improperly managed.
- Slightly harder to statically analyse or validate compared to structured formats like JSON or YAML.
Proposed solution
Enhance Hazaar\Application\Config
to support reading .php
config files that return an associative array.
Example:
// config/app.php
return [
'debug' => true,
'cache_dir' => __DIR__ . '/../cache',
];
The loader will check for .php files and require them, expecting a returned array that will be merged into the config tree.
This format should be supported transparently alongside existing formats, and file extension priority can be defined or overridden if needed.
Examples
$config = new \Hazaar\Application\Config('/path/to/config');
echo $config->get('debug'); // true
Directory structure
config/
app.php
database.php
Priority/Severity
-
High (This will bring a huge increase in performance/productivity/usability/legislative cover) -
Medium (This will bring a good increase in performance/productivity/usability) -
Low (anything else e.g., trivial, minor improvements)