Recommend this page to a friend! |
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
Classes of Smoren Freelight | > | Nested PHP Accessor | > | Download .zip .tar.gz | > | Support forum | > | Blog (1) | > | Latest changes |
|
Groups | Applications | Files |
Groups |
Algorithms | Numerical and statistical algorithms | View top rated classes |
Libraries | Frameworks and libraries of cooperating classes | View top rated classes |
PHP 7 | Classes using PHP 7 specific features | View top rated classes |
PSR | Packages that implement PHP Standard Recommendations by FIG | View top rated classes |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
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 | / | src |
File | Role | Description | ||
---|---|---|---|---|
Components (3 files) | ||||
Exceptions (1 file) | ||||
Factories (2 files) | ||||
Helpers (3 files) | ||||
Interfaces (4 files) |
Files | / | src | / | Components |
File | Role | Description |
---|---|---|
NestedAccessor.php | Class | Class source |
NestedArrayStorage.php | Class | Class source |
SilentNestedAccessor.php | Class | Class source |
Files | / | src | / | Factories |
File | Role | Description |
---|---|---|
NestedAccessorFactory.php | Class | Class source |
SilentNestedAccessorFactory.php | Class | Class source |
Files | / | src | / | Helpers |
File | Role | Description |
---|---|---|
ArrayHelper.php | Class | Class source |
NestedAccess.php | Class | Class source |
NestedHelper.php | Class | Class source |
Files | / | 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 | / | 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 | / | 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 | / | tests | / | unit | / | Fixtures |
File | Role | Description |
---|---|---|
ClassWithAccessibleProperties.php | Class | Class source |
Download all files: nested-accessor-php.tar.gz nested-accessor-php.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|
Files |
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 | / | src |
File | Role | Description | ||
---|---|---|---|---|
Components (3 files) | ||||
Exceptions (1 file) | ||||
Factories (2 files) | ||||
Helpers (3 files) | ||||
Interfaces (4 files) |
Files | / | src | / | Components |
File | Role | Description |
---|---|---|
NestedAccessor.php | Class | Class source |
NestedArrayStorage.php | Class | Class source |
SilentNestedAccessor.php | Class | Class source |
Files | / | src | / | Factories |
File | Role | Description |
---|---|---|
NestedAccessorFactory.php | Class | Class source |
SilentNestedAccessorFactory.php | Class | Class source |
Files | / | src | / | Helpers |
File | Role | Description |
---|---|---|
ArrayHelper.php | Class | Class source |
NestedAccess.php | Class | Class source |
NestedHelper.php | Class | Class source |
Files | / | 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 | / | 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 | / | 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 | / | tests | / | unit | / | Fixtures |
File | Role | Description |
---|---|---|
ClassWithAccessibleProperties.php | Class | Class source |
Download all files: nested-accessor-php.tar.gz nested-accessor-php.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|