Completed
Push — develop ( b74491...9e8dd2 )
by
unknown
12:13
created

EventAwareConverter::__construct()   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 2
1
<?php
2
3
/*
4
 * This file is part of Sulu.
5
 *
6
 * (c) MASSIVE ART WebServices GmbH
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Sulu\Bundle\ArticleBundle\Elasticsearch;
13
14
use ONGR\ElasticsearchBundle\Mapping\MetadataCollector;
15
use ONGR\ElasticsearchBundle\Result\Converter;
16
use ONGR\ElasticsearchBundle\Service\Manager;
17
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
18
19
/**
20
 * Extends converter of "ongr/elasticsearch-bundle" to throw event when converting array to document.
21
 */
22
class EventAwareConverter extends Converter
23
{
24
    const EVENT_POST_CONVERT_TO_DOCUMENT = 'es.post_convert_to_document';
25
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $dispatcher;
30
31
    public function __construct(MetadataCollector $metadataCollector, EventDispatcherInterface $dispatcher)
32
    {
33
        parent::__construct($metadataCollector);
34
35
        $this->dispatcher = $dispatcher;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function convertToDocument($rawData, Manager $manager)
42
    {
43
        $document = parent::convertToDocument($rawData, $manager);
44
        $this->dispatcher->dispatch(
45
            self::EVENT_POST_CONVERT_TO_DOCUMENT,
46
            new PostConvertToDocumentEvent($rawData, $document, $manager)
47
        );
48
49
        return $document;
50
    }
51
}
52