1<?php
2
3namespace Elastica\ResultSet;
4
5use Elastica\Query;
6use Elastica\Response;
7use Elastica\ResultSet;
8
9class ProcessingBuilder implements BuilderInterface
10{
11    /**
12     * @var BuilderInterface
13     */
14    private $builder;
15
16    /**
17     * @var ProcessorInterface
18     */
19    private $processor;
20
21    public function __construct(BuilderInterface $builder, ProcessorInterface $processor)
22    {
23        $this->builder = $builder;
24        $this->processor = $processor;
25    }
26
27    /**
28     * Runs any registered transformers on the ResultSet before
29     * returning it, allowing the transformers to inject additional
30     * data into each Result.
31     */
32    public function buildResultSet(Response $response, Query $query): ResultSet
33    {
34        $resultSet = $this->builder->buildResultSet($response, $query);
35
36        $this->processor->process($resultSet);
37
38        return $resultSet;
39    }
40}
41