solophp/configs
Composer 安装命令:
composer require solophp/configs
包简介
Simple and flexible configuration management library with dot notation support
README 文档
README
Solo Configs is a simple PHP package for managing configuration settings in your application. It provides easy access to configuration values using dot notation and supports default values if a key is not found.
Requirements
- PHP 8.1 or higher
Installation
You can install the package via Composer:
composer require solophp/configs
Usage
Create an instance of Configs by passing an array of configurations. You can then retrieve values using dot notation.
Basic Usage
use Solo\Configs\Configs; // Create a new instance with your configurations $configs = new Configs([ 'database' => [ 'host' => 'localhost', 'username' => 'root', 'password' => 'secret', ], 'app' => [ 'name' => 'My Application', 'debug' => true, 'settings' => [ 'timezone' => 'UTC' ] ] ]); // Get values using dot notation $dbHost = $configs->get('database.host'); // 'localhost' $appName = $configs->get('app.name'); // 'My Application' $timezone = $configs->get('app.settings.timezone'); // 'UTC' // Using default values $cache = $configs->get('cache.enabled', false); // false (using default) // Get entire sections $dbConfig = $configs->get('database'); // Returns entire database array $allConfigs = $configs->get(); // Returns all configurations // Note: Magic method access is limited in PHP due to property name restrictions // It's recommended to use the get() method directly for best compatibility
Configuration Structure
Your configuration array can be as deeply nested as needed:
$configs = new Configs([ 'session' => [ 'lifetime' => 86400, 'options' => [ 'secure' => true, 'httponly' => true, 'samesite' => 'Lax' ] ], 'cache' => [ 'driver' => 'redis', 'connection' => [ 'host' => 'localhost', 'port' => 6379 ] ] ]);
API Reference
Methods
Constructor
public function __construct(array $configs)
Creates a new Configs instance.
Parameters:
array $configs: Configuration array
Get Configuration Value
public function get(string $key = '', mixed $default = null): mixed
Retrieves a configuration value using dot notation.
Parameters:
string $key: Configuration key using dot notation (optional)mixed $default: Default value if key not found
Returns: Configuration value or default if not found
Magic Property Access
public function __get(string $key): mixed
Magic method for property access (limited functionality in PHP).
Parameters:
string $key: Configuration key
Returns: Configuration value or null if not found
Note: Due to PHP limitations with property names containing special characters, it's recommended to use the get() method directly.
Development
Running Tests
composer test
Code Style
Check code style:
composer cs
Fix code style:
composer cs-fix
License
This package is open-source and available under the MIT License.
solophp/configs 适用场景与选型建议
solophp/configs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「configuration」 「array」 「Settings」 「dot-notation」 「configs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 solophp/configs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 solophp/configs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 solophp/configs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
Configuration component
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
Convert array or camel case to underscore, or underscore to others.
统计信息
- 总下载量: 75
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-16