Download the PHP package jojo1981/data-resolver without Composer
On this page you can find all versions of the php package jojo1981/data-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package data-resolver
Generic extensible data resolver
Author: Joost Nijhuis [[email protected]](mailto:[email protected])
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
orflatten
using a predicate. - get the next value (boolean) with
all
,some
,none
for sequences andhasProperty
for objects - get the next value (integer) with
count
for sequences and orstrlen
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
orstrlen
- 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 withregisterPropertyHandler
.
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 withregisterSequenceHandler
.
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
Library
Composer
Basic usage
A simple example how to use the resolver.
More complex examples will be added here to the documentation in the future.