PHPackages                             lukaszmakuch/aggregator - 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. lukaszmakuch/aggregator

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

lukaszmakuch/aggregator
=======================

Makes generating statistics database agnostic and flexible.

v0.10(9y ago)019MITPHP

Since Jun 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lukaszmakuch/aggregator)[ Packagist](https://packagist.org/packages/lukaszmakuch/aggregator)[ RSS](/packages/lukaszmakuch-aggregator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (11)Used By (0)

[![travis](https://camo.githubusercontent.com/8aa04920ba2a2f0d605e96a50fd9564f1a1d1ea8e575234ea4303245afcf0bdc/68747470733a2f2f7472617669732d63692e6f72672f6c756b61737a6d616b7563682f61676772656761746f722e737667)](https://travis-ci.org/lukaszmakuch/aggregator)

Aggregator
==========

[](#aggregator)

Makes generating statistics database agnostic and flexible.

This document briefly describes the library. For more details, check unit tests.

Why is it interesting?
----------------------

[](#why-is-it-interesting)

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"
        }
    }]
}
```

About the library
-----------------

[](#about-the-library)

### Built-in aggregators

[](#built-in-aggregators)

There are few basic aggregators built-in

#### Counter

[](#counter)

*lukaszmakuch\\Aggregator\\Impl\\Counter\\Counter*

Counts all given subjects.

#### Limit

[](#limit)

*lukaszmakuch\\Aggregator\\Impl\\Limit\\Limit*

Limits the number of aggregated subjects. It is visible for visitors.

#### TransparentLimit

[](#transparentlimit)

*lukaszmakuch\\Aggregator\\Impl\\Limit\\TransparentLimit*

Limits the number of aggregated subjects. It is invisible for visitors.

#### Percentage

[](#percentage)

*lukaszmakuch\\Aggregator\\Impl\\Percentage\\Percentage*

Calculates a percentage value of subjects that meet some requirement.

#### ListAggregator

[](#listaggregator)

*lukaszmakuch\\Aggregator\\Impl\\ListAggregator\\ListAggregator*

Generates a list of text representations of subjects separated with some given delimiter.

#### PropertyList

[](#propertylist)

*lukaszmakuch\\Aggregator\\Impl\\PropertyList\\PropertyList*

List of properties of aggregated subjects. Uses a PropertyReader to read them.

#### Filter

[](#filter)

*lukaszmakuch\\Aggregator\\Impl\\Filter\\Filter*

Takes into account only those subjects that meet the given requirement.

#### GroupingAggregator

[](#groupingaggregator)

*lukaszmakuch\\Aggregator\\Impl\\GroupingAggregator\\GroupingAggregator*

Groups subjects by some property.

#### HierarchicalAggregator

[](#hierarchicalaggregator)

*lukaszmakuch\\Aggregator\\Impl\\HierarchicalAggregator\\HierarchicalAggregator*

Supports parent-children relationships.

#### ProjectionAggregator

[](#projectionaggregator)

*lukaszmakuch\\Aggregator\\Impl\\Projection\\ProjectionAggregator*

Before passing subjects to some other aggregator, gets a a different of them.

#### ConditionalAggregator

[](#conditionalaggregator)

*lukaszmakuch\\Aggregator\\Impl\\ConditionalAggregator\\ConditionalAggregator*

Equals one of two given aggregators, depending on the given PredicateAggregator.

#### Container

[](#container)

*lukaszmakuch\\Aggregator\\Impl\\Container\\Container*

Holds many actual aggregators and passes to them all what's passed to it.

#### WithCustomLabel

[](#withcustomlabel)

*lukaszmakuch\\Aggregator\\LabelGenerator\\WithCustomLabel*

Decorates some aggregator with a label generated by the provided label generator.

### LabelGenerator

[](#labelgenerator)

An instance of [*lukaszmakuch\\TextGenerator\\TextGenerator*](https://github.com/lukaszmakuch/text-generator) is used by an AggregatorVisitor to generate labels for aggregators.

#### LabelGeneratorBuilder

[](#labelgeneratorbuilder)

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()
;
```

### ScalarPresenter

[](#scalarpresenter)

Generates a representation of the given aggregator as a scalar value or an array of scalar values.

#### ScalarPresenterBuilder

[](#scalarpresenterbuilder)

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();
```

### XmlPresenter

[](#xmlpresenter)

Generates an XML representation of a given aggregator as a String.

#### XmlPresenterBuilder

[](#xmlpresenterbuilder)

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();
```

How to install
--------------

[](#how-to-install)

```
$ composer require lukaszmakuch/aggregator

```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

10

Last Release

3508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e08a5c26bd9824a0345f417660e2d1146f044c886266daf2dd0901720fbcf32?d=identicon)[lukaszmakuch](/maintainers/lukaszmakuch)

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/lukaszmakuch-aggregator/health.svg)

```
[![Health](https://phpackages.com/badges/lukaszmakuch-aggregator/health.svg)](https://phpackages.com/packages/lukaszmakuch-aggregator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
