Completed
Push — master ( 10f04f...aa9f0e )
by Simonas
02:13
created

ObjectIterator::doInitialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Result;
13
14
use Doctrine\Common\Collections\AbstractLazyCollection;
15
use Doctrine\Common\Collections\ArrayCollection;
16
17
/**
18
 * ObjectIterator class.
19
 */
20
class ObjectIterator extends AbstractLazyCollection
21
{
22
    /**
23
     * @var Converter
24
     */
25
    private $converter;
26
27
    /**
28
     * @var array Aliases information.
29
     */
30
    private $alias;
31
32
    /**
33
     * Converts raw document data to objects when requested.
34
     *
35
     * @param Converter $converter
36
     * @param array     $objects
37
     * @param array     $alias
38
     */
39
    public function __construct($converter, $objects, $alias)
40
    {
41
        $this->converter = $converter;
42
        $this->alias = $alias;
43
        $this->collection = new ArrayCollection($objects);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    protected function convertDocument(array $document)
50
    {
51
        return $this->converter->assignArrayToObject(
52
            $document,
53
            new $this->alias['namespace'](),
54
            $this->alias['aliases']
55
        );
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    protected function doInitialize()
62
    {
63
        $this->collection = $this->collection->map(function ($rawObject) {
64
            return $this->convertDocument($rawObject);
65
        });
66
    }
67
}
68