Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/renoki-co/laravel-explicit-array
Improved Laravel dot notation for explicit array keys.
https://github.com/renoki-co/laravel-explicit-array
arr array laravel php support
Last synced: about 1 month ago
JSON representation
Improved Laravel dot notation for explicit array keys.
- Host: GitHub
- URL: https://github.com/renoki-co/laravel-explicit-array
- Owner: renoki-co
- License: apache-2.0
- Created: 2021-10-27T19:28:18.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-27T04:27:40.000Z (7 months ago)
- Last Synced: 2024-10-12T21:07:39.866Z (2 months ago)
- Topics: arr, array, laravel, php, support
- Language: PHP
- Homepage:
- Size: 67.4 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
Laravel Explicit Array
======================![CI](https://github.com/renoki-co/laravel-explicit-array/workflows/CI/badge.svg?branch=master)
[![codecov](https://codecov.io/gh/renoki-co/laravel-explicit-array/branch/master/graph/badge.svg)](https://codecov.io/gh/renoki-co/laravel-explicit-array/branch/master)
[![StyleCI](https://github.styleci.io/repos/421948177/shield?branch=master)](https://github.styleci.io/repos/421948177)
[![Latest Stable Version](https://poser.pugx.org/renoki-co/laravel-explicit-array/v/stable)](https://packagist.org/packages/renoki-co/laravel-explicit-array)
[![Total Downloads](https://poser.pugx.org/renoki-co/laravel-explicit-array/downloads)](https://packagist.org/packages/renoki-co/laravel-explicit-array)
[![Monthly Downloads](https://poser.pugx.org/renoki-co/laravel-explicit-array/d/monthly)](https://packagist.org/packages/renoki-co/laravel-explicit-array)
[![License](https://poser.pugx.org/renoki-co/laravel-explicit-array/license)](https://packagist.org/packages/renoki-co/laravel-explicit-array)Improved Laravel dot notation for explicit array keys.
## 🚀 Installation
You can install the package via composer:
```bash
composer require renoki-co/laravel-explicit-array
```## 🙌 Usage
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`.
```php
$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.**
```php
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:
```php
use RenokiCo\ExplicitArray\Arr;Arr::set($annotations, 'annotations.nested."some.annotation.com/ttl"', 1800);
// [
// 'annotations' => [
// 'nested' => [
// 'some.annotation.com/ttl' => 1800
// ]
// ]
// ]
```## 🐛 Testing
``` bash
vendor/bin/phpunit
```## 🤝 Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## 🔒 Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## 🎉 Credits
- [Alex Renoki](https://github.com/rennokki)
- [All Contributors](../../contributors)