Completed
Pull Request — 6.0-dev (#868)
by Simonas
01:38
created

Converter::convertArrayToDocument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\Mapping;
13
14
use ONGR\ElasticsearchBundle\Annotation\NestedType;
15
use ONGR\ElasticsearchBundle\Annotation\ObjectType;
16
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17
use Symfony\Component\Serializer\Serializer;
18
use Symfony\Component\Serializer\SerializerAwareTrait;
19
use Symfony\Component\Serializer\SerializerInterface;
20
21
/**
22
 * This class converts array to document object.
23
 */
24
class Converter
25
{
26
    use SerializerAwareTrait;
27
28
    private $documentParser;
29
30
    public function __construct(DocumentParser $documentParser)
31
    {
32
        $this->documentParser = $documentParser;
33
    }
34
35
    public function convertArrayToDocument(string $namespace, array $raw, Serializer $serializer)
36
    {
37
        return $serializer->denormalize($raw, $namespace);
38
    }
39
40
    public function convertDocumentToArray($document, Serializer $serializer): array
41
    {
42
        return $serializer->normalize($document, 'array');
43
    }
44
}
45