elephox / configuration
Elephox 配置库。
v0.7.0
2022-10-21 15:11 UTC
Requires
- php: ^8.1 <8.3
- ext-json: *
- elephox/collection: dev-develop
- elephox/files: dev-develop
- elephox/oor: dev-develop
- elephox/support: dev-develop
- jetbrains/phpstorm-attributes: ^1.0
- vlucas/phpdotenv: ^5.4
This package is auto-updated.
Last update: 2024-09-18 22:05:52 UTC
README
此模块由 Elephox 用于加载配置文件并提供对其值的轻松访问。它受到了 .NETs 配置包 的启发。
示例
<?php use Elephox\Configuration\ConfigurationManager; use Elephox\Configuration\Json\JsonFileConfigurationSource; $configurationManager = new ConfigurationManager(); $configurationManager->add(new JsonFileConfigurationSource('config.json')); $configurationManager->add(new JsonFileConfigurationSource('config.local.json', optional: true)); $configurationRoot = $configurationManager->build(); echo $configurationRoot['database:host']; // 'localhost' echo $configurationRoot['database:port']; // 3306 echo $configurationRoot['env']; // 'local'
config.json
{ "env": "production", "database": { "host": "production-server", "port": 3306 } }
config.local.json
{ "env": "local", "database": { "host": "localhost" } }