phpnomad/config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

phpnomad/config

最新稳定版本:1.0.0

Composer 安装命令:

composer require phpnomad/config

包简介

README 文档

README

Latest Version Total Downloads PHP Version License

phpnomad/config is a strategy-based configuration layer for PHP applications. It splits configuration into two separate concerns, one for how values are stored and looked up and another for how files are read from disk. Both live behind interfaces, so you can change either one without touching the code that consumes configuration values.

The package defines ConfigStrategy for storage and lookup, ConfigFileLoaderStrategy for file loading, and a ConfigService that ties them together. Keys are accessed with dot-notation, so nested structures like app.mailer.host work out of a single get call. The base package has no runtime dependencies. Concrete file-loading backends live in separate packages.

Installation

composer require phpnomad/config

Quick Start

Once you have a ConfigStrategy implementation, register a namespace of config data and read values back with dot-notation keys.

use PHPNomad\Config\Interfaces\ConfigStrategy;

/** @var ConfigStrategy $config */
$config->register('app', [
    'debug'  => false,
    'locale' => 'en_US',
    'mailer' => [
        'host' => 'smtp.example.com',
        'port' => 587,
    ],
]);

$config->get('app.debug');              // false
$config->get('app.mailer.host');        // 'smtp.example.com'
$config->get('app.mailer.timeout', 30); // 30 (default fallback)
$config->has('app.mailer.host');        // true

ConfigStrategy is an interface. Pair it with a concrete implementation like phpnomad/json-config-integration for JSON files, or phpnomad/array-json-config for a basic arrays and JSON setup. You can also implement ConfigStrategy directly against any storage backend you need.

Key Concepts

  • ConfigStrategy registers a top-level key with an array of config data and reads single values with dot-notation lookups. get() accepts a default for missing keys. has() reports whether a key resolves to a value.
  • ConfigFileLoaderStrategy turns a file path into an array of configuration data. This keeps file-format decisions (JSON, PHP, YAML, or anything else) separate from how the data is stored.
  • ConfigService takes a ConfigStrategy and a ConfigFileLoaderStrategy in its constructor. Call registerConfig($key, $path) to load a file through the loader and register its contents under a namespace in the strategy.
  • ConfigException is raised when loading or registering configuration fails, so consumers have a single exception type to catch around config setup.

Documentation

Full documentation, including the interface contracts and guidance on writing your own strategies, lives at phpnomad.com.

License

MIT. See LICENSE.txt.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-18