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

XmlSerializationVisitorFactory::setFormatOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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