Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 58 | All time: 10,535 This week: 74 |
Version | License | PHP version | Categories | |||
nested-accessor-php 1.0 | MIT/X Consortium ... | 7.4 | Algorithms, Libraries, PHP 7, PSR |
Accessor for getting and setting values of nested data structures (arrays or objects).
composer require smoren/nested-accessor
composer install
composer test-init
composer test
use Smoren\NestedAccessor\Components\NestedAccessor;
$source = [
'data' => [
'id' => 1,
'name' => 'Countries classifier',
'extra' => null,
'country_names' => ['Russia', 'Belarus'],
],
'countries' => [
[
'name' => 'Russia',
'cities' => [
[
'name' => 'Moscow',
'extra' => [
'codes' => [
['value' => 7495],
['value' => 7499],
],
],
],
[
'name' => 'Petersburg',
'extra' => [
'codes' => [
['value' => 7812],
],
],
],
],
],
[
'name' => 'Belarus',
'cities' => [
[
'name' => 'Minsk',
'extra' => [
'codes' => [
['value' => 375017],
],
],
],
],
],
]
];
$accessor = new NestedAccessor($input);
echo $accessor->get('data.name'); // 'Countries classifier'
print_r($accessor->get('countries.name')); // ['Russia', 'Belarus']
print_r($accessor->get('countries.cities.name')); // ['Moscow', 'Petersburg', 'Minsk']
print_r($accessor->get('countries.cities.extra.codes.value')); // [7495, 7499, 7812, 375017]
var_dump($accessor->isset('data.name')); // true
var_dump($accessor->isset('data.extra')); // false
var_dump($accessor->isset('this.path.not.exist')); // false
var_dump($accessor->exist('data.name')); // true
var_dump($accessor->exist('data.extra')); // true
var_dump($accessor->exist('this.path.not.exist')); // false
$accessor->set('data.name', 'New name');
echo $accessor->get('data.name'); // 'New name'
$accessor->append('data.country_names', 'Mexico');
echo $accessor->get('data.country_names'); // ['Russia', 'Belarus', 'Mexico']
$accessor->delete('data.name');
var_dump($accessor->exist('data.name')); // false
Files (30) |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (5 directories) | ||||
tests (3 files, 2 directories) | ||||
.travis.yml | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (30) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Components (3 files) | ||||
Exceptions (1 file) | ||||
Factories (2 files) | ||||
Helpers (3 files) | ||||
Interfaces (4 files) |
Files (30) | / | src | / | Components |
File | Role | Description |
---|---|---|
NestedAccessor.php | Class | Class source |
NestedArrayStorage.php | Class | Class source |
SilentNestedAccessor.php | Class | Class source |
Files (30) | / | src | / | Factories |
File | Role | Description |
---|---|---|
NestedAccessorFactory.php | Class | Class source |
SilentNestedAccessorFactory.php | Class | Class source |
Files (30) | / | src | / | Helpers |
File | Role | Description |
---|---|---|
ArrayHelper.php | Class | Class source |
NestedAccess.php | Class | Class source |
NestedHelper.php | Class | Class source |
Files (30) | / | src | / | Interfaces |
File | Role | Description |
---|---|---|
NestedAccessorFactoryInterface.php | Class | Class source |
NestedAccessorInterface.php | Class | Class source |
SilentNestedAccessorFactoryInterface.php | Class | Class source |
SilentNestedAccessorInterface.php | Class | Class source |
Files (30) | / | tests |
File | Role | Description | ||
---|---|---|---|---|
unit (6 files, 1 directory) | ||||
_support (1 file) | ||||
coding_standard.xml | Data | Auxiliary data | ||
unit.suite.yml | Data | Auxiliary data | ||
_bootstrap.php | Aux. | Auxiliary script |
Files (30) | / | tests | / | unit |
File | Role | Description | ||
---|---|---|---|---|
Fixtures (1 file) | ||||
NestedAccessorExceptionTest.php | Class | Class source | ||
NestedAccessorTest.php | Class | Class source | ||
NestedFactoryTest.php | Class | Class source | ||
NestedHelperTest.php | Class | Class source | ||
NestedStorageTest.php | Class | Class source | ||
SilentNestedAccessorTest.php | Class | Class source |
Files (30) | / | tests | / | unit | / | Fixtures |
File | Role | Description |
---|---|---|
ClassWithAccessibleProperties.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
nested-accessor-php-2023-03-10.zip 22KB | |
nested-accessor-php-2023-03-10.tar.gz 13KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.