yansongda/supports
Supports is a small PHP utility library from the yansongda ecosystem that simplifies working with arrays, configuration, and pipelines. It provides handy helpers for array access and manipulation, config handling, and pipeline processing, making it useful for Laravel or PHP projects that need lightw...
Yansongda\Supports\Json 工具类:Json::encode()/Json::decode() 薄封装原生 json_encode()/json_decode(),失败即抛 \JsonException(code 为 JSON_ERROR_*),不再需要靠 false 返回值或 json_last_error() 判断失败 (#42)
Json::encode(mixed $value, int $flags = JSON_UNESCAPED_UNICODE, int $depth = 512): string
Json::decode(string $json, bool $assoc = true, int $depth = 512, int $flags = 0): mixed(默认返回关联数组)
encode() 默认 flags 为 JSON_UNESCAPED_UNICODE(原生为 0,中文会被转义为 \uXXXX),传 0 可还原原生转义行为;$flags/$depth 参数名对齐原生函数,其余行为与原生一致
使用示例(运行环境要求不变,仍为 PHP >= 8.2):
use Yansongda\Supports\Json;
Json::encode(['name' => '中文']); // {"name":"中文"}
Json::decode('{"name":"中文"}'); // ['name' => '中文']
Json::decode('{bad'); // 抛 \JsonException,原生此处返回 null
ext-simplexml 与 ext-libxml 依赖(Collection::toXml()/Arr::wrapXml() 实际所需,此前未显式声明)Collection::toQueryString() 方法:查询串构造(等价原 toString() 能力,Arr::toString() 静态方法不变)Collection::toString() 标记 [@deprecated](https://github.com/deprecated)(phpdoc + PHP 8 原生 #[\Deprecated] 注解,PHP 8.4+ 调用时自动触发 deprecation 提示):继续可用,实现改为委托新增的 toQueryString(),行为不变;将在后续大版本移除,建议迁移Arr::sortRecursive() 内部实现由引用遍历改写为键位赋值形态,Arr::shuffle()/Collection::valueRetriever() 内部回调闭包签名补全:均为内部实现优化,签名与可观察行为不变Collection::except() 改为变参签名(mixed ...$keys):主用形态行为不变,仅 except(['a'], ['b']) 由旧静默丢弃多余实参改为执行期 TypeErrorPipeline::through() 改为变参签名(mixed ...$pipes):主用形态行为不变,仅 through(['a'], 'b') 由旧静默丢弃改为执行期 TypeError;through([$obj, 'method']) 语义由"对象 + 字符串两管道"修正为"单个 callable-array 管道"(与 illuminate 主流用法一致)Str::ascii()/Str::slug()/Str::kebab() 在 strict_types=1 下对任意输入必抛 TypeError 的 bug(charsArray() 数字字符串键被 PHP 规范化为 int 键,str_replace() 收到 int 抛错)增加 guzzle 依赖,增加 HasHttpRequest Trait
How can I help you explore Laravel packages today?