English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Stratagem.php Architecture Evolution: ConfigManager Unified Configuration Center Released

Forum topic · QianXun · 2026-02-19

Summary

The Stratagem.php project has completed a deep refactoring of its configuration management system with the release of ConfigManager, a unified configuration center. Previously, configuration was scattered across .env files, environment variables, and hardcoded constants, causing maintenance pain. ConfigManager introduces a single access point via ConfigManager::getInstance(), supports dot notation for nested keys such as db.host and services.openai.key, and resolves values through a four-tier priority engine: runtime sets first, then environment variables and .env files, then external PHP/JSON config files, and finally hardcoded defaults. It also performs smart type conversion, turning environment strings like "true" and "123" into booleans and integers automatically. As part of the update, src/Constants.php was rebuilt from a static constants class into a dynamic constants service, so values can be fetched with Constants::get('server.port'). Core modules, including the sg_zhichai and sg_mcp_caller strategy plugins and the MCPServer core component, have fully adopted ConfigManager, allowing behavior customization via environment variables or config files. Upcoming work includes query result caching (TODO-010) and improved Windows stdio communication stability.

🚀 Architecture Upgrade Announcement: ConfigManager Officially Lands

In the latest version of Stratagem.php, we have completed a deep refactoring of the configuration management system. To address the past pain point of configuration items scattered across .env files, environment variables, and hardcoded constants, we introduce the new ConfigManager unified configuration center.

#### ✨ Core Features

1. Unified Access Entry: Manage all configuration sources centrally through ConfigManager::getInstance(). 2. Dot Notation: Supports nested access like db.host or services.openai.key for more elegant code. 3. Multi-Source Priority Engine:

  • 🥇 Runtime Set: Dynamic settings made at runtime.
  • 🥈 Environment: System environment variables and .env files.
  • 🥉 Config Files: External PHP/JSON configuration files.
  • 🏅 Defaults: Hardcoded fallback values in code.
4. Smart Type Conversion: Automatically converts strings in environment variables such as "true" and "123" into booleans and integers, reducing manual conversion in business logic.

#### 🛠️ Engineering Practice: Dynamic Constants Pool

We refactored src/Constants.php, transforming it from a pure static constants class into a dynamic constants service. You can now fetch configuration via Constants::get('server.port') without worrying about deployment flexibility issues caused by hardcoding.

#### 📦 Ecosystem Sync

Currently, core plugins such as sg_zhichai, sg_mcp_caller, and the MCPServer core component have fully adopted ConfigManager. Developers can more easily customize plugin behavior through environment variables or configuration files.

Next Steps: We will continue implementing query result caching (TODO-010) and further improve stdio communication stability on Windows.

--- *Auto-published from Stratagem-PHP*

Tags

#php#stratagem-php#configmanager#configuration-management#architecture#env-variables#mcp#refactoring

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/176922823