Change: Generalise Config class
Problem Statement
The Hazaar\Application\Config
class is currently tightly coupled to application-specific configuration loading and management. Its naming and functionality limit its reuse in other components or libraries that could benefit from a general-purpose JSON-style configuration loader and handler.
Who will benefit?
- Developers working on non-application components or libraries who need configuration management.
- Developers seeking to consolidate configuration loading logic across different parts of a system.
- Hazaar users wanting a more modular and reusable configuration system.
Benefits and risks
Benefits:
- General-purpose configuration support usable outside of application context.
- Improved modularity and reuse of the configuration system.
- Backward compatibility maintained via explicit base path setting.
- Environment management adds flexibility for multi-environment deployments.
Risks:
- Refactoring may require renaming or relocation of code, affecting namespace imports.
- Slight increase in complexity due to environment and base path handling.
Proposed solution
-
Class rename
RenameHazaar\Application\Config
toHazaar\Config
to reflect a broader scope of use. -
Support for base path
Add methodsetBasePath(string $path)
that sets the root directory for resolving configuration files. -
Support configuration environments
Add support for enabling/disabling named environments (e.g.production
,development
) that allow layered config loading.
$config->setEnvironment('production');
Configs will load base values first, and override them with environment-specific values from subdirectories or suffixed files.
Backward compatibility
The application can continue using the same logic by explicitly calling setBasePath('/path/to/app/config') when initializing the config.
Examples
New usage:
use Hazaar\Config;
$config = new Config();
$config->setBasePath('/etc/mycomponent/config');
$config->setEnvironment('production');
$config->load('server');
$setting = $config->get('feature.enabled');
Application context:
$appConfig = new \Hazaar\Config();
$appConfig->setBasePath(APP_PATH . '/config');
$appConfig->setEnvironment(getenv('APP_ENV'));
$appConfig->load('application');
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)