定制 dschuppelius/php-config-toolkit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dschuppelius/php-config-toolkit

最新稳定版本:v0.2.19

Composer 安装命令:

composer require dschuppelius/php-config-toolkit

包简介

Ein Toolkit für JSON-basierte Konfigurationsverwaltung

README 文档

README

PHP Version License

Ein JSON-basiertes Konfigurationsverwaltungs-Toolkit mit Plugin-basierter Architektur für verschiedene Konfigurationsdateiformate.

Features

  • Singleton-Pattern: Zentraler ConfigLoader für konsistente Konfigurationsverwaltung
  • Plugin-System: Automatische Erkennung und Laden von ConfigType-Klassen
  • Typ-Casting: Unterstützt float, int, timestamp, date, datetime, bool, array, json und string
  • 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

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

  1. Erstelle eine neue Klasse in src/ConfigTypes/ die ConfigTypeAbstract erweitert
  2. Implementiere die Methoden matches(), parse() und validate()
  3. 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

统计信息

  • 总下载量: 546
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-09