定制 phpnomad/json-config-integration 二次开发

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

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

phpnomad/json-config-integration

最新稳定版本:1.1.1

Composer 安装命令:

composer require phpnomad/json-config-integration

包简介

description

README 文档

README

Latest Version Total Downloads PHP Version License

phpnomad/json-config-integration wires JSON-file-backed configuration into a PHPNomad application. It binds the strategies from phpnomad/array-json-config to the interfaces defined in phpnomad/config, then registers a set of JSON files against ConfigService during the loader bootstrap. Install this package when you want configuration values stored in JSON files on disk and accessible anywhere via dot-notation keys.

Installation

composer require phpnomad/json-config-integration

What This Provides

  • A single ConfigInitializer class that binds ArrayConfigStrategy to ConfigStrategy and JsonFileLoader to ConfigFileLoaderStrategy in the DI container.
  • During load(), it walks the constructor-supplied ['namespace' => '/path/to/file.json'] map and calls ConfigService::registerConfig() for each entry, so every file is parsed and indexed in one pass.
  • Implementations of HasClassDefinitions, Loadable, and CanSetContainer, so the initializer drops into any phpnomad/loader bootstrap sequence without extra glue.

Requirements

  • phpnomad/config
  • phpnomad/array-json-config
  • phpnomad/di ^2.0
  • phpnomad/loader ^1.0 || ^2.0

Usage

Register the initializer with your application's bootstrapper and hand it a map of namespace keys to JSON file paths.

<?php

use PHPNomad\Component\JsonConfigIntegration\ConfigInitializer;
use PHPNomad\Config\Services\ConfigService;
use PHPNomad\Loader\Bootstrapper;

$configInitializer = new ConfigInitializer([
    'app'      => __DIR__ . '/config/app.json',
    'database' => __DIR__ . '/config/database.json',
    'mailer'   => __DIR__ . '/config/mailer.json',
]);

$bootstrapper = new Bootstrapper($container, $configInitializer);
$bootstrapper->load();

/** @var ConfigService $config */
$config = $container->get(ConfigService::class);

$config->get('app.debug');             // value from app.json
$config->get('database.default.host'); // nested lookup into database.json
$config->get('mailer.port', 587);      // default fallback

Each file is parsed once during load() and its contents are stored under the namespace key you provided, so consumers read values through ConfigService without re-reading the filesystem.

Documentation

Full documentation for PHPNomad lives at phpnomad.com.

License

MIT. See LICENSE.

统计信息

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

GitHub 信息

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

其他信息

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