This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A PHP configuration management library that loads and manages configuration files from a directory. The library provides two main classes:
- Config: Static configuration loader and accessor
- ConfigEditor: Extends Config to allow appending new configuration values to files
The Config class loads all .php files from a specified directory on instantiation. Each file should return an associative array. Files are keyed by their lowercase filename (without extension).
Default File Handling: The system now uses config.php as the default configuration file (changed from default.php). The default file is:
- Loaded first before other configuration files
- Accessible via
Config::get()without specifying the config file parameter - Defined by the
$defaultparameter in the constructor (defaults to 'config')
Fallback Behavior: For backward compatibility, if config.php doesn't exist, the system will fall back to looking for default.php (see Core/Config.php:75-76).
Both classes use static properties to store configurations globally:
$configs- Stores all loaded configuration arrays keyed by filename$configFilePaths- Maps config keys to their file paths$configDirPath- Stores the configuration directory path
This means once initialized, configs are accessible statically throughout the application without passing instances.
The ConfigEditor::addToConfig() method has important limitations:
- Append-only: Currently disabled editing existing keys due to key duplication issues (Core/ConfigEditor.php:33-34)
- File format requirements: Config files must end with
];or a RuntimeException is thrown - String values only: The current implementation only handles string values in the format
'key' => 'value'(Core/ConfigEditor.php:104)
Generate API documentation from PHPDoc comments:
composer require --dev clean/phpdoc-md
vendor/bin/phpdoc-md generate Core > docs/README.mdThe project uses clean/phpdoc-md to generate markdown documentation from class PHPDoc comments. Generated docs are stored in the docs/ directory.
Test the library using the example file:
php Example.phpThis demonstrates:
- Loading configs from
lib/Config/directory - Retrieving values with
Config::get() - Setting custom runtime values with
Config::set() - Adding new config entries with
ConfigEditor::addToConfig() - Reloading configs with
Config::reload()
The Yohns\Lang\Text class has been refactored to use Config internally for language file management, eliminating code duplication.
- Text creates a separate
Configinstance pointing to the language directory (e.g.,lib/Lang/) - Language files (en.php, es.php, etc.) are loaded into the same static
Config::$configsarray - Both config and language data coexist in the same Config storage
Shared Static Storage: Since Config uses static properties, both application configs and language files share the same storage. This means:
- Language files are accessible via
Config::get('key', 'en')orConfig::get('key', 'es') - The
$defaultparameter changes when Text is initialized, affecting which config is used forConfig::get('key')calls without a second parameter - Always specify the config file explicitly when mixing Text and Config:
Config::get('siteName', 'config')
Auto-Update Feature: When a phrase is missing from the English language file, ConfigEditor automatically appends it using the same append-only mechanism as regular configs.
Recommended structure for language files:
lib/
├── Config/ # Application configs
│ ├── config.php
│ └── db_tables.php
└── Lang/ # Language files (separate directory)
├── en.php
├── es.php
└── fr.php
use Yohns\Core\Config;
use Yohns\Lang\Text;
// Load application configs
new Config(__DIR__ . '/lib/Config');
// Load language files
new Text(__DIR__ . '/lib/Lang', 'es');
// Use translations
echo Text::L('welcome'); // Gets from Spanish
echo Text::L('hello', [':name' => 'Juan']); // With replacements
// Access configs (specify file explicitly)
echo Config::get('siteName', 'config');- Namespace:
Yohns\CoreandYohns\Lang - PSR-4 Autoload:
Yohns\maps toYohns/directory - PHP Requirement: ^8.0
Configuration files in lib/Config/ should return arrays:
<?php
return [
'key' => 'value',
'another_key' => 'another_value'
];Multiple config files are supported (e.g., db_tables.php, language.php, config.php). Access them by filename without extension:
Config::get('key', 'db_tables'); // From db_tables.php
Config::get('key'); // From config.php (default)