Makes generating statistics database agnostic and flexible.
This document briefly describes the library. For more details, check unit tests.
A simple aggregator
$aggregator = new GroupingAggregator(
new AgeReader(),
new ListAggregator(new NameReader(), ", ")
);
given
$aggregator->aggregate(new Cat(['name' => 'Henry', 'age' => 5]));
$aggregator->aggregate(new Cat(['name' => 'Mruczek', 'age' => 2]));
$aggregator->aggregate(new Cat(['name' => 'Meow', 'age' => 2]));
$aggregator->aggregate(new Cat(['name' => 'Bob', 'age' => 2]));
$aggregator->aggregate(new Cat(['name' => 'Tim', 'age' => 5]));
gives
{
"type": "group",
"label": "grouped by age",
"data": [{
"type": "subjects_with_common_properties",
"label": "age 5",
"data": {
"type": "list",
"label": "list",
"data": "Henry, Tim"
}
}, {
"type": "subjects_with_common_properties",
"label": "age 2",
"data": {
"type": "list",
"label": "list",
"data": "Mruczek, Meow, Bob"
}
}]
}
There are few basic aggregators built-in
lukaszmakuch\Aggregator\Impl\Counter\Counter
Counts all given subjects.
lukaszmakuch\Aggregator\Impl\Limit\Limit
Limits the number of aggregated subjects. It is visible for visitors.
lukaszmakuch\Aggregator\Impl\Limit\TransparentLimit
Limits the number of aggregated subjects. It is invisible for visitors.
lukaszmakuch\Aggregator\Impl\Percentage\Percentage
Calculates a percentage value of subjects that meet some requirement.
lukaszmakuch\Aggregator\Impl\ListAggregator\ListAggregator
Generates a list of text representations of subjects separated with some given delimiter.
lukaszmakuch\Aggregator\Impl\PropertyList\PropertyList
List of properties of aggregated subjects. Uses a PropertyReader to read them.
lukaszmakuch\Aggregator\Impl\Filter\Filter
Takes into account only those subjects that meet the given requirement.
lukaszmakuch\Aggregator\Impl\GroupingAggregator\GroupingAggregator
Groups subjects by some property.
lukaszmakuch\Aggregator\Impl\HierarchicalAggregator\HierarchicalAggregator
Supports parent-children relationships.
lukaszmakuch\Aggregator\Impl\Projection\ProjectionAggregator
Before passing subjects to some other aggregator, gets a a different of them.
lukaszmakuch\Aggregator\Impl\ConditionalAggregator\ConditionalAggregator
Equals one of two given aggregators, depending on the given PredicateAggregator.
lukaszmakuch\Aggregator\Impl\Container\Container
Holds many actual aggregators and passes to them all what's passed to it.
lukaszmakuch\Aggregator\LabelGenerator\WithCustomLabel
Decorates some aggregator with a label generated by the provided label generator.
An instance of lukaszmakuch\TextGenerator\TextGenerator is used by an AggregatorVisitor to generate labels for aggregators.
Because of the complex nature of possible labels, there's a builder that makes it easier to get a generator that fits your needs.
$labelGeneratingVisitor = (new DefaultLabelGeneratorBuilder())
->registerDependency(
PropertyToTextConverterUser::class,
(new ClassBasedTextGeneratorProxy())->registerActualGenerator(
Age::class,
new AgeToTextConverter()
)
)
->registerLabelGeneratorPrototype(
CustomAggregator::class,
new CustomAggregatorLabelGenerator()
)
->build()
;
Generates a representation of the given aggregator as a scalar value or an array of scalar values.
Because of the complex nature of possible aggregator composites, there's a builder that makes it easier to get a scalar presenter that fits your needs.
$presentingVisitor = (new DefaultScalarPresenterBuilder())
->registerDependency(
LabelingVisitorUser::class,
$labelingVisitor
)
->registerExtension(new ExtensionImpl(
CustomAggregator::class,
new CustomAggregatorPresenter(),
"some_custom_aggregator"
))
->build();
Generates an XML representation of a given aggregator as a String.
Because of the complex nature of possible aggregator composites, there's a builder that makes it easier to get an xml presenter that fits your needs.
$xmlPresenter =
(new DefaultXmlPresenterBuilder())
->registerDependency(
LabelingVisitorUser::class,
$labelingVisitor
)
->registerActualPresenter(
CustomAggregator::class,
new CustomAggregatorXmlPresenter(),
)
->build();
$ composer require lukaszmakuch/aggregator