lemaur/laravel-typed-config
最新稳定版本:0.1.0
Composer 安装命令:
composer require lemaur/laravel-typed-config
包简介
README 文档
README
This package provides an object-oriented way to retrieve the configuration data with the right type.
If you are familiar with static analysis tool like phpstan, you've probably encountered Cannot cast mixed to string error (or similar).
This is usually happen when you try to cast a value returned from a method/function with a mixed return type.
Most of the time, in my personal case, the method is config() and following you can see an example:
$myValue = (string) config('my-app.my-value'); // or $myValue = (string) config()->get('my-app.my-value');
With this package you can get a string value (and not only string) directly from the configuration like:
$myValue = config()->string('my-app.my-value');
Support Me
Hey folks,
Do you like this package? Do you find it useful, and it fits well in your project?
I am glad to help you, and I would be so grateful if you considered supporting my work.
You can even choose 😃:
- You can sponsor me 😎 with a monthly subscription.
- You can buy me a coffee ☕ or a pizza 🍕 just for this package.
- You can plant trees 🌴. By using this link we will both receive 30 trees for free and the planet (and me) will thank you.
- You can "Star ⭐" this repository (it's free 😉).
Installation
You can install the package via composer:
composer require lemaur/laravel-typed-config
Usage
Retrieving Stringable Configuration Value
You may use the string method to retrieve the configuration data as an instance of Illuminate\Support\Stringable:
$name = config()->string('my-app.name');
Retrieving Boolean Configuration Value
You may use the boolean method to retrieve the configuration data as a boolean. The boolean method returns true for 1, "1", true, "true", "on", and "yes". All other values will return false:
$archived = config()->boolean('my-app.archived');
Retrieving Integer Configuration Value
You may use the integer method to retrieve the configuration data as an integer:
$count = config()->integer('my-app.count');
Retrieving Float Configuration Value
You may use the float method to retrieve the configuration data as a float:
$amount = config()->float('my-app.amount');
Retrieving Date Configuration Value
You may use the date method to retrieve the configuration data as a Carbon instance:
$birthday = config()->date('my-app.birthday');
The second and third arguments accepted by the date method may be used to specify the date's format and timezone, respectively:
$elapsed = config()->date('my-app.elapsed', '!H:i', 'Europe/Madrid');
In case of an invalid format, an InvalidArgumentException will be thrown.
Retrieving Enum Configuration Value
You may use the enum method to retrieve the configuration data as a PHP enum instance.
In case of an invalid value or the enum does not have a backing value that matches the input value, null will be returned.
The enum method accepts the name of the input value and the enum class as its first and second arguments:
use App\Enums\Status; $status = config()->enum('my-app.status', Status::class);
Retrieving Configuration Value as a Collection
You may use the collect method to retrieve the configuration data as an Illuminate\Support\Collection instance:
$data = config()->collect('my-app.data');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
lemaur/laravel-typed-config 适用场景与选型建议
lemaur/laravel-typed-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.15k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「config」 「laravel」 「lemaur」 「laravel-typed-config」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lemaur/laravel-typed-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lemaur/laravel-typed-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lemaur/laravel-typed-config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Utils to load, parse and work with configuration on Mezzio projects
Server environment detection based on config array-file
Single and multi-dimensional parameter bag with dot-path access for PHP.
Trait to support creating complex nested class structures from JSON/YAML objects.
统计信息
- 总下载量: 1.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-29