Field selector for PHP Object
, (*1)
Description
The library for filter complex array/hash or object and return the actual fields you want to use., (*2)
If you have a large variables contained with unused values which not necessary to used. The library will helps by filter out all the unused fields and left your fields on return variable., (*3)
The library can traverse the complex array or nested array in any level of array/hash or object., (*4)
For a deeper knowledge of how to use this package, follow this index:, (*5)
Installation
You can install the package via composer require
command:, (*6)
composer require jeurboy/object-field-selector
Or simply add it to your composer.json dependences and run composer update
:, (*7)
"require": {
"jeurboy/object-field-selector": "*"
}
Usage
For simple usage. Just create returned schema and send to DataParser;, (*8)
$parser = new Jeurboy\SimpleObjectConverter\SchemaParser();
$parser->addSchema("test1");
$token = $parser->getParsedSchema();
$data = [
'test1' => "11234",
'test2' => "22222"
];
$DataParser = new Jeurboy\SimpleObjectConverter\DataParser();
$return = $DataParser->getOutput($data, $token);
print_r($return);
You will see following result., (*9)
Array
(
[test1] => 11234
)
If you have nested Array just pass .(Dot) in your schema., (*10)
$parser = new Jeurboy\SimpleObjectConverter\SchemaParser();
$parser->addSchema("test1.eee");
$token = $parser->getParsedSchema();
$data = [
'test1' => [
'eee' => "hello holy",
]
];
$DataParser = new Jeurboy\SimpleObjectConverter\DataParser();
$return = $DataParser->getOutput($data, $token);
print_r($return);
You will get result array like this., (*11)
Array
(
[test1] => Array
(
[eee] => hello holy
)
)
If there are multiple field inside input array, use comma(,) to define more fields., (*12)
$parser = new Jeurboy\SimpleObjectConverter\SchemaParser();
$parser->addSchema("test1");
$token = $parser->getParsedSchema();
$data = [
'test1' => [
'eee' => "hello holy",
'fff' => "hello holy",
]
];
$DataParser = new Jeurboy\SimpleObjectConverter\DataParser();
$return = $DataParser->getOutput($data, $token);
print_r($return);
You will see the result has multiple field returned., (*13)
Array
(
[test1] => Array
(
[eee] => hello holy
[fff] => hello holy
)
)
The library also support object inside sequencial array., (*14)
$parser = new Jeurboy\SimpleObjectConverter\SchemaParser();
$parser->addSchema("test1.hello");
$token = $parser->getParsedSchema();
$data = [
'test1' => [
[
"hello" => "world1",
"ok" => "google1",
],[
"hello" => "world2",
"ok" => "google2",
],
]
];
$DataParser = new Jeurboy\SimpleObjectConverter\DataParser();
$return = $DataParser->getOutput($data, $token);
print_r($return);
Result is, (*15)
Array
(
[test1] => Array
(
[0] => Array
(
[hello] => world1
)
[1] => Array
(
[hello] => world2
)
)
)
You can see all test case in example/example.php files., (*16)