PHP code example of lukaszmakuch / aggregator

1. Go to this page and download the library: Download lukaszmakuch/aggregator 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/ */

    

lukaszmakuch / aggregator example snippets


$aggregator = new GroupingAggregator(
    new AgeReader(),
    new ListAggregator(new NameReader(), ", ")
);

$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]));

$labelGeneratingVisitor = (new DefaultLabelGeneratorBuilder())
    ->registerDependency(
        PropertyToTextConverterUser::class,
        (new ClassBasedTextGeneratorProxy())->registerActualGenerator(
            Age::class,
            new AgeToTextConverter()
        )
    )
    ->registerLabelGeneratorPrototype(
        CustomAggregator::class,
        new CustomAggregatorLabelGenerator()
    )
    ->build()
;

$presentingVisitor = (new DefaultScalarPresenterBuilder())
    ->registerDependency(
        LabelingVisitorUser::class,
        $labelingVisitor
    )
    ->registerExtension(new ExtensionImpl(
        CustomAggregator::class,
        new CustomAggregatorPresenter(),
        "some_custom_aggregator"
    ))
    ->build();

$xmlPresenter =
    (new DefaultXmlPresenterBuilder())
    ->registerDependency(
        LabelingVisitorUser::class,
        $labelingVisitor
    )
    ->registerActualPresenter(
        CustomAggregator::class,
        new CustomAggregatorXmlPresenter(),
    )
    ->build();