PHPackages                             jojo1981/data-resolver - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jojo1981/data-resolver

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jojo1981/data-resolver
======================

Generic extensible data resolver

3.1.0(1mo ago)113.6k↓28.8%1MITPHPPHP ^8.3CI passing

Since Oct 23Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/jojo1981/data-resolver)[ Packagist](https://packagist.org/packages/jojo1981/data-resolver)[ RSS](/packages/jojo1981-data-resolver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (12)Versions (16)Used By (1)

Generic extensible data resolver
================================

[](#generic-extensible-data-resolver)

[![Build Status](https://github.com/jojo1981/data-resolver/actions/workflows/build.yml/badge.svg)](https://github.com/jojo1981/data-resolver/actions/workflows/build.yml)[![Coverage Status](https://camo.githubusercontent.com/3944a7f2dfc8dc698e0bcdf99f26fdaf87626ff000f16ac0685c545656f27b2e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6a6f6a6f313938312f646174612d7265736f6c7665722f62616467652e737667)](https://coveralls.io/github/jojo1981/data-resolver)[![Latest Stable Version](https://camo.githubusercontent.com/76fad4b924ef7262f344db1b2c36e1685fa0324f801b0c776044402138b46786/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6a6f313938312f646174612d7265736f6c7665722f762f737461626c65)](https://packagist.org/packages/jojo1981/data-resolver)[![Total Downloads](https://camo.githubusercontent.com/f71f70c53145d78df5399adb97a816d76f929a41cbce77add07fca4ac7890105/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6a6f313938312f646174612d7265736f6c7665722f646f776e6c6f616473)](https://packagist.org/packages/jojo1981/data-resolver)[![License](https://camo.githubusercontent.com/70ea62416759910b5eb4cf9eee00aacad1e4b73dc7d29dc4fda48d5765e1375d/68747470733a2f2f706f7365722e707567782e6f72672f6a6f6a6f313938312f646174612d7265736f6c7665722f6c6963656e7365)](https://packagist.org/packages/jojo1981/data-resolver)

Author: Joost Nijhuis &lt;&gt;

The data resolver is a resolver which will be declarative created and used to extract data in steps from a tree structure.
The data resolver will perform all extract operations linear and in order.
The next operation will be performed on the last result etc...
Some operations are to extract data from an `object` and others for extracting data of a `sequence`.
This library has factory class to get a resolver builder and start building a resolver.
Also custom `comparator`, `merge`, `property` and `sequence` handlers can be registered.

The extract operations are:

- get the next value with `get` using a single property
- get the next value with `get` using multiple properties (The data resolver tries to merge the result)
- get the next value with a `find`, `filter` or `flatten` using a predicate.
- get the next value (boolean) with `all`, `some`, `none` for sequences and `hasProperty` for objects
- get the next value (integer) with `count` for sequences and or `strlen` for strings
- get the next value (float) with `sum` for sequences of integers/floats
- get the next value (mixed) with `callback` for mixed data

The predicates are:

- equals($referenceValue)
- notEquals($referenceValue)
- greaterThan($referenceValue)
- greaterThanOrEquals($referenceValue)
- lessThan($referenceValue)
- lessThanOrEquals($referenceValue)
- isTrue()
- isFalse()
- isTruly()
- isFalsely()
- isNull()
- isNotNull()
- callback(callable $callback)
- not(PredicateBuilderInterface $predicateBuilder)
- some(PredicateBuilderInterface $predicateBuilder)
- all(PredicateBuilderInterface $predicateBuilder)
- none(PredicateBuilderInterface $predicateBuilder)
- in(array $expectedValues)
- notIn(array $expectedValues)
- isEmpty()
- isNotEmpty()
- hasCount(int $expectedCount)
- hasNotCount(int $expectedCount)
- stringStartsWith(string $prefix, bool $caseSensitive = true)
- stringEndsWith(string $suffix, bool $caseSensitive = true)
- stringEndsWith(string $suffix, bool $caseSensitive = true)
- stringContains(string $subString, bool $caseSensitive = true)
- stringMatchesRegex(string $pattern)
- hasProperty(string $propertyName)

The flow:

- Create 1 generic factory instance and add optionally customizations.
- Get 1 resolver builder factory with `getResolverBuilderFactory`
    (The generic factory will be frozen and can not be customized anymore, this way the generic factory will always produced a resolver builder factory provided with the same setup)
- Get for every to build resolver a fresh resolver builder from the resolver builder factory with `create`, `compose`, `get`, `filter`, `flatten`, `find`, `all`, `none`, `some`, `count` or `strlen`
- The resolver builder must be build to get a resolver. This resolver is immutable and can only be used to resolver data from a tree structure.
- Use the resolver with the `resolve` method and give it some data

To create a predicate builder call `or`, `and`, `not` or `where` on the resolver builder.

Setup generic factory instance:

- Invoke `registerPropertyHandler` to register a custom property handler
- Invoke `registerSequenceHandler` to register a custom sequence handler
- Invoke `useDefaultPropertyHandlers` when you have custom property handlers and register them with `registerPropertyHandler`.
    This is not needed when you do not have custom property handlers registered.
    You can invoke this method before or after the registration of the custom property handlers in order to determine the priority of the handlers
    When this method is *NOT* invoked and there are custom property handlers registered the default property handlers are *NOT* registered
- Invoke `useDefaultSequenceHandlers` when you have custom sequence handlers and register them with `registerSequenceHandler`.
    This is not needed when you do not have custom sequence handlers registered.
    You can invoke this method before or after the registration of the sequence property handlers in order to determine the priority of the handlers
    When this method is *NOT* invoked and there are custom sequence handlers registered the default sequence handlers are *NOT* registered
- Invoke `setMergeHandler` to inject a custom merge handler (replaces the default)
- Invoke `setNamingStrategy` to inject a custom naming strategy (replaces the default)
- Invoke `setComparator` to inject a custom comparator (replaces the default)

Get resolver builder factory from generic factory:

- Invoke `getResolverBuilderFactory` to get the resolver builder factory which can be used to create multiple resolver builders

Create customizations:

- A property handler is a class which implement interface: `\Jojo1981\DataResolver\Handler\PropertyHandlerInterface`
- A sequence handler is a class which implement interface: `\Jojo1981\DataResolver\Handler\SequenceHandlerInterface`
- A merge handler is a class which implement interface: `\Jojo1981\DataResolver\Handler\MergeHandlerInterface`
- A naming strategy is a class which implement interface: `\Jojo1981\DataResolver\NamingStrategy\NamingStrategyInterface`
- A comparator is a class which implement interface: `\Jojo1981\DataResolver\Comparator\ComparatorInterface`

Installation
------------

[](#installation)

### Library

[](#library)

```
git clone https://github.com/jojo1981/data-resolver.git
```

### Composer

[](#composer)

[Install PHP Composer](https://getcomposer.org/doc/00-intro.md)

```
composer require jojo1981/data-resolver
```

Basic usage
-----------

[](#basic-usage)

A simple example how to use the resolver.
More complex examples will be added here to the documentation in the future.

```
