1. Go to this page and download the library: Download jojo1981/data-resolver library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jojo1981 / data-resolver example snippets
Data = [
'data' => [
['name' => 'John', 'age' => 40, 'gender' => 'M'],
['name' => 'Jane', 'age' => 35, 'gender' => 'F'],
['name' => 'Rachel', 'age' => 15, 'gender' => 'F'],
['name' => 'Dennis', 'age' => 12, 'gender' => 'M'],
['name' => 'Bob', 'age' => 6, 'gender' => 'M']
]
];
$genericFactory = new \Jojo1981\DataResolver\Factory();
$resolverBuilderFactory = $genericFactory->getResolverBuilderFactory();
$dataResolverBuilder = $resolverBuilderFactory->get('data');
$agePredicateBuilder1 = $resolverBuilderFactory->where('age')->greaterThanOrEquals(35);
$agePredicateBuilder2 = $resolverBuilderFactory->where('age')->greaterThanOrEquals(45);
// will be all persons
\print_r($dataResolverBuilder->build()->resolve($testData));
// Will be 5
\var_dump($dataResolverBuilder->count()->resolve($testData));
// filtered data contains John and Jane
\print_r($dataResolverBuilder->filter($agePredicateBuilder1)->build()->resolve($testData));
// empty array
\print_r($dataResolverBuilder->filter($agePredicateBuilder2)->build()->resolve($testData));
// Will be true
\var_dump($dataResolverBuilder->some($agePredicateBuilder1)->resolve($testData));
// Will be false
\var_dump($dataResolverBuilder->all($agePredicateBuilder1)->resolve($testData));
// Will be false
\var_dump($dataResolverBuilder->none($agePredicateBuilder1)->resolve($testData));
// Will be 3
\var_dump(
$resolverBuilderFactory
->find($resolverBuilderFactory->where('age')->equals(6))
->get('name')
->strlen()
->resolve($testData['data'])
);
// more examples to come...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.