Completed
Pull Request — master (#923)
by Asmir
04:23 queued 01:58
created

XmlSerializationVisitorFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 52.38%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 11
cts 21
cp 0.5238
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getVisitor() 0 10 1
A setDefaultRootName() 0 4 1
A setDefaultEncoding() 0 3 1
A setDefaultVersion() 0 3 1
A setFormatOutput() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright 2016 Johannes M. Schmitt <[email protected]>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
namespace JMS\Serializer\VisitorFactory;
22
23
use JMS\Serializer\Accessor\AccessorStrategyInterface;
24
use JMS\Serializer\GraphNavigatorInterface;
25
use JMS\Serializer\JsonSerializationVisitor;
26
use JMS\Serializer\SerializationContext;
27
use JMS\Serializer\SerializationVisitorInterface;
28
use JMS\Serializer\XmlSerializationVisitor;
29
30
/**
31
 *
32
 * @author Asmir Mustafic <[email protected]>
33
 */
34
class XmlSerializationVisitorFactory implements SerializationVisitorFactory
35
{
36
    private $defaultRootName = 'result';
37
    private $defaultVersion = '1.0';
38
    private $defaultEncoding = 'UTF-8';
39
    private $formatOutput = true;
40
    private $defaultRootNamespace;
41
42 116
    public function getVisitor(GraphNavigatorInterface $navigator, SerializationContext $context): SerializationVisitorInterface
43
    {
44 116
        return new XmlSerializationVisitor(
45 116
            $navigator,
46 116
            $context,
47 116
            $this->formatOutput,
48 116
            $this->defaultEncoding,
49 116
            $this->defaultVersion,
50 116
            $this->defaultRootName,
51 116
            $this->defaultRootNamespace
52
        );
53
    }
54
55
    public function setDefaultRootName(string $name, ?string $namespace = null)
56
    {
57
        $this->defaultRootName = $name;
58
        $this->defaultRootNamespace = $namespace;
59
    }
60
61
    public function setDefaultVersion(string $version)
62
    {
63
        $this->defaultVersion = $version;
64
    }
65
66
    public function setDefaultEncoding(string $encoding)
67
    {
68
        $this->defaultEncoding = $encoding;
69
    }
70
71 1
    public function setFormatOutput(bool $formatOutput)
72
    {
73 1
        $this->formatOutput = (boolean)$formatOutput;
74 1
    }
75
}
76