https://github.com/dschoenbauer/dot-notation
Given a complicated data structure, allows easy and safe access to data via dot notation. This library is a compilation of other Dot Notation libraries, taking the best feature from each and incorporating them here.
https://github.com/dschoenbauer/dot-notation
composer dot-notation packagist psr-4
Last synced: about 1 month ago
JSON representation
Given a complicated data structure, allows easy and safe access to data via dot notation. This library is a compilation of other Dot Notation libraries, taking the best feature from each and incorporating them here.
- Host: GitHub
- URL: https://github.com/dschoenbauer/dot-notation
- Owner: dschoenbauer
- Created: 2016-11-25T15:13:47.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2017-05-03T16:15:28.000Z (almost 8 years ago)
- Last Synced: 2025-02-25T15:06:58.186Z (2 months ago)
- Topics: composer, dot-notation, packagist, psr-4
- Language: PHP
- Homepage:
- Size: 644 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dot Notation
[](https://travis-ci.org/dschoenbauer/dot-notation)
[](https://coveralls.io/github/dschoenbauer/dot-notation?branch=develop)
[](https://github.com/dschoenbauer/dot-notation)
[](https://packagist.org/packages/dschoenbauer/dot-notation)
[](https://github.com/dschoenbauer/dot-notation/releases)[](https://github.com/dschoenbauer/dot-notation)
[](https://packagist.org/packages/dschoenbauer/dot-notation)
[](https://github.com/dschoenbauer/dot-notation/releases)## Purpose
Simplifies access to large array structures## Installation
````
composer require dschoenbauer/dot-notation
````## Testing
````
./vendor/bin/phpunit tests
````## Example
```
use DSchoenbauer\DotNotation\ArrayDotNotation;$mongoConnection = [
'mongo' => [
'default' => [ 'user' => 'username', 'password' => 's3cr3t' ]
]
];
$config = new ArrayDotNotation($mongoConnection);
--- or ---
$config = ArrayDotNotation::with($mongoConnection);
```### GET
```
// Get plain value
$user = $config->get('mongo.default.user');
/*
$user = 'username';
*/// Get array value
$mongoDefault = $config->get('mongo.default');
/*
$mongoDefault = ['user' => 'username', 'password' => 's3cr3t'];
*/
```### SET
````
$configDump = $config->set('mongo.numbers', [2, 3, 5, 7, 11])->getData();
/*
$configDump = [
'mongo' => [
'default' => [ 'user' => 'username', 'password' => 's3cr3t' ],
'numbers' => [2, 3, 5, 7, 11]
],
'title' => 'Dot Notation'
];
*/
````### MERGE
````
$configDump = $config->merge('mongo.default', ['user' => 'otherUser','active' => true])->getData();
/*
$configDump = [
'mongo' => [
'default' => [ 'user' => 'otherUser', 'password' => 's3cr3t','active' => true ]
],
'title' => 'Dot Notation'
];
*/
````### REMOVE
````
$configDump = $config->remove('mongo.default.user')->getData();
/*
$configDump = [
'mongo' => [
'default' => [ 'password' => 's3cr3t' ]
],
'title' => 'Dot Notation'
];
*/
````### NOTATION TYPE
````
// Tired of dots? Change it.
$user = $config->setNotationType(',')->get('mongo,default,user');
/*
$user = 'username';
*/
````### WITH
````
//Functional fluent fun
$user = ArrayDotNotation::with($mongoConnection)->get('mongo.default.user');
/*
$user = 'username';
*/````
### HAS
````
// Validates that the dot notation path is present in the data.
$isPresent = $config->has('mongo,default,user');
/*
$isPresent = true;
*/
````