phpnomad/json-config-integration
最新稳定版本:1.1.1
Composer 安装命令:
composer require phpnomad/json-config-integration
包简介
description
README 文档
README
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
ConfigInitializerclass that bindsArrayConfigStrategytoConfigStrategyandJsonFileLoadertoConfigFileLoaderStrategyin the DI container. - During
load(), it walks the constructor-supplied['namespace' => '/path/to/file.json']map and callsConfigService::registerConfig()for each entry, so every file is parsed and indexed in one pass. - Implementations of
HasClassDefinitions,Loadable, andCanSetContainer, so the initializer drops into anyphpnomad/loaderbootstrap sequence without extra glue.
Requirements
phpnomad/configphpnomad/array-json-configphpnomad/di^2.0phpnomad/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
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-18