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    /**
22     * @param BuilderInterface   $builder
23     * @param ProcessorInterface $processor
24     */
25    public function __construct(BuilderInterface $builder, ProcessorInterface $processor)
26    {
27        $this->builder = $builder;
28        $this->processor = $processor;
29    }
30
31    /**
32     * Runs any registered transformers on the ResultSet before
33     * returning it, allowing the transformers to inject additional
34     * data into each Result.
35     *
36     * @param Response $response
37     * @param Query    $query
38     *
39     * @return ResultSet
40     */
41    public function buildResultSet(Response $response, Query $query): ResultSet
42    {
43        $resultSet = $this->builder->buildResultSet($response, $query);
44
45        $this->processor->process($resultSet);
46
47        return $resultSet;
48    }
49}
50