renoki-co / laravel-explicit-array
改进Laravel点符号以实现显式数组键。
1.0.0
2022-02-03 20:05 UTC
Requires
- illuminate/support: ^9.0
Requires (Dev)
- mockery/mockery: ^1.5
- orchestra/testbench: ^7.0
- phpunit/phpunit: ^9.0
- vimeo/psalm: 4.19.0
This package is auto-updated.
Last update: 2024-08-27 05:05:31 UTC
README
改进Laravel点符号以实现显式数组键。
🚀 安装
您可以通过composer安装此包
composer require renoki-co/laravel-explicit-array
🙌 使用
Laravel原始的Arr::set()
方法将键中的点视为嵌套值的分隔符。这是预期的。这些部分将创建一个嵌套值some -> annotation -> com/ttl
,其值为1800
。
$annotations = [ 'some.annotation.com/ttl' => 900, ]; Arr::set($annotations, 'some.annotation.com/ttl', 1800); // Current result // [ // 'some' => [ // 'annotation' => [ // 'com/ttl' => 1800 // ] // ] // ] // Desired result // [ // 'some.annotation.com/ttl' => 1800 // ]
为了解决这个问题,Explicit Array引入了一个新的RenokiCo\ExplicitArray\Arr
类,它修改了::set()
方法,确保读取引号之间的段作为文字键。
您可以使用此类作为您的常规Arr
类,因为它扩展了原始的\Illuminate\Support\Arr
类。
use RenokiCo\ExplicitArray\Arr; Arr::set($annotations, '"some.annotation.com/ttl"', 1800); // [ // 'some.annotation.com/ttl' => 1800 // ]
这可以与混合段一起工作,这意味着只要您保持点在引号之外,您就可以指定嵌套值
use RenokiCo\ExplicitArray\Arr; Arr::set($annotations, 'annotations.nested."some.annotation.com/ttl"', 1800); // [ // 'annotations' => [ // 'nested' => [ // 'some.annotation.com/ttl' => 1800 // ] // ] // ]
🐛 测试
vendor/bin/phpunit
🤝 贡献
请参阅CONTRIBUTING以获取详细信息。
🔒 安全性
如果您发现任何安全相关的问题,请通过电子邮件alex@renoki.org联系,而不是使用问题跟踪器。