dschuppelius / php-config-toolkit
Ein Toolkit für JSON-basierte Konfigurationsverwaltung
Installs: 638
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/dschuppelius/php-config-toolkit
Requires
- php: >=8.0 <8.5
- dschuppelius/php-error-toolkit: ^2.0
Requires (Dev)
- phpunit/phpunit: ^11.3@dev
This package is auto-updated.
Last update: 2026-01-10 22:14:52 UTC
README
Ein JSON-basiertes Konfigurationsverwaltungs-Toolkit mit Plugin-basierter Architektur für verschiedene Konfigurationsdateiformate.
Features
- Singleton-Pattern: Zentraler
ConfigLoaderfür konsistente Konfigurationsverwaltung - Plugin-System: Automatische Erkennung und Laden von ConfigType-Klassen
- Typ-Casting: Unterstützt
float,int,timestamp,date,datetime,bool,array,jsonundstring - Validierung: Automatische Validierung gegen den passenden ConfigType
- Mehrere Konfigurationsformate: Strukturierte Configs, Executable-Definitionen, Postman-Collections u.v.m.
Installation
composer require dschuppelius/php-config-toolkit
Anforderungen
- PHP 8.0 - 8.5
- dschuppelius/php-error-toolkit ^1.2
Verwendung
Konfiguration laden
use ConfigToolkit\ConfigLoader; $loader = ConfigLoader::getInstance(); $loader->loadConfigFile('config.json'); // Wert abrufen $value = $loader->get('Section', 'key');
Konfiguration validieren
use ConfigToolkit\ConfigValidator; $errors = ConfigValidator::validate('config.json'); if (empty($errors)) { echo "Konfiguration ist gültig!"; } else { foreach ($errors as $error) { echo "Fehler: $error\n"; } }
Beispiel-Konfigurationsdatei
{
"Database": [
{"key": "host", "value": "localhost", "type": "text", "enabled": true},
{"key": "port", "value": "3306", "type": "int", "enabled": true},
{"key": "debug", "value": "true", "type": "bool", "enabled": true}
],
"Cache": [
{"key": "ttl", "value": "3600", "type": "int", "enabled": true}
]
}
Unterstützte ConfigTypes
| ConfigType | Beschreibung |
|---|---|
StructuredConfigType |
Standard key/value/enabled-Struktur (Fallback) |
AdvancedStructuredConfigType |
Erweiterte Struktur mit flachen Arrays |
ExecutableConfigType |
Executable-Pfade mit Argumenten |
CrossPlatformExecutableConfigType |
Plattformspezifische Executables (Windows/Linux) |
PostmanConfigType |
Postman Collection-Exporte |
Eigene ConfigTypes erstellen
- Erstelle eine neue Klasse in
src/ConfigTypes/dieConfigTypeAbstracterweitert - Implementiere die Methoden
matches(),parse()undvalidate() - Der ClassLoader erkennt und registriert die Klasse automatisch
use ConfigToolkit\Contracts\Abstracts\ConfigTypeAbstract; class MyConfigType extends ConfigTypeAbstract { public static function matches(array $data): bool { // Prüfe ob diese Klasse die Datenstruktur verarbeiten kann return isset($data['mySpecialKey']); } public function parse(array $data): array { // Daten in nutzbares Array umwandeln return $data; } public function validate(array $data): array { // Fehler-Array zurückgeben (leer wenn valide) return []; } }
Tests ausführen
composer test # oder vendor/bin/phpunit
Lizenz
MIT License - siehe LICENSE für Details.
Autor
Daniel Jörg Schuppelius - schuppelius.org