Change: Generalise Config class #339

Closed
opened 2025-05-14 00:37:30 +00:00 by jamie · 4 comments
jamie commented 2025-05-14 00:37:30 +00:00 (Migrated from git.hazaar.io)

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

  1. Class rename
    Rename Hazaar\Application\Config to Hazaar\Config to reflect a broader scope of use.

  2. Support for base path
    Add method setBasePath(string $path) that sets the root directory for resolving configuration files.

  3. 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)
## 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 1. **Class rename** Rename `Hazaar\Application\Config` to `Hazaar\Config` to reflect a broader scope of use. 2. **Support for base path** Add method `setBasePath(string $path)` that sets the root directory for resolving configuration files. 3. **Support configuration environments** Add support for enabling/disabling named environments (e.g. `production`, `development`) that allow layered config loading. ```php $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: ```php use Hazaar\Config; $config = new Config(); $config->setBasePath('/etc/mycomponent/config'); $config->setEnvironment('production'); $config->load('server'); $setting = $config->get('feature.enabled'); ``` ### Application context: ```php $appConfig = new \Hazaar\Config(); $appConfig->setBasePath(APP_PATH . '/config'); $appConfig->setEnvironment(getenv('APP_ENV')); $appConfig->load('application'); ``` ## Priority/Severity * [x] 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)
jamie commented 2025-05-14 00:37:31 +00:00 (Migrated from git.hazaar.io)

assigned to @jamie

assigned to @jamie
jamie commented 2025-05-14 00:37:38 +00:00 (Migrated from git.hazaar.io)

created branch 339-change-generalise-config-class to address this issue

created branch [`339-change-generalise-config-class`](/hazaar/framework/-/compare/master...339-change-generalise-config-class) to address this issue
jamie commented 2025-05-14 00:37:45 +00:00 (Migrated from git.hazaar.io)

mentioned in merge request !227

mentioned in merge request !227
jamie commented 2025-05-14 04:55:48 +00:00 (Migrated from git.hazaar.io)

mentioned in commit 6f7746e4a5

mentioned in commit 6f7746e4a533f1b80a249a8c72687261ae353d59
jamie (Migrated from git.hazaar.io) closed this issue 2025-05-14 04:55:48 +00:00
jamie self-assigned this 2025-09-04 01:13:36 +00:00
jamie removed their assignment 2025-09-04 01:13:44 +00:00
jamie self-assigned this 2025-09-04 01:13:49 +00:00
jamie removed their assignment 2025-09-04 01:13:54 +00:00
jamie self-assigned this 2025-09-04 01:14:01 +00:00
jamie removed their assignment 2025-09-04 01:14:06 +00:00
jamie self-assigned this 2025-09-04 01:14:22 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/framework#339
No description provided.