Improved Laravel dot notation for explicit array keys.
renoki-co/laravel-explicit-array is a Laravel package for improved laravel dot notation for explicit array keys..
It currently has 8 GitHub stars and 863 downloads on Packagist (latest version 1.0.0).
Install it with composer require renoki-co/laravel-explicit-array.
Discover more Laravel packages by renoki-co
or browse all Laravel packages to compare alternatives.
Last updated
Improved Laravel dot notation for explicit array keys.
You can install the package via composer:
composer require renoki-co/laravel-explicit-array
The original Laravel's Arr::set() method treats the dots within the key as separators for nested values. This is expected. The segments will create a nested value some -> annotation -> com/ttl with a value of 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
// ]
To fix this, Explicit Array introduces a new RenokiCo\ExplicitArray\Arr class, which altered the ::set() method, so that will make sure to read the segments between quotes as literal keys.
You may use this class as your regular Arr class because it extends the original \Illuminate\Support\Arr class.
use RenokiCo\ExplicitArray\Arr;
Arr::set($annotations, '"some.annotation.com/ttl"', 1800);
// [
// 'some.annotation.com/ttl' => 1800
// ]
This can work with mixed segments, meaning that as long as you keep the dots outside the quotes, you can specify nested values:
use RenokiCo\ExplicitArray\Arr;
Arr::set($annotations, 'annotations.nested."some.annotation.com/ttl"', 1800);
// [
// 'annotations' => [
// 'nested' => [
// 'some.annotation.com/ttl' => 1800
// ]
// ]
// ]
vendor/bin/phpunit
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.