1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\Visitor\Factory;
6
7use JMS\Serializer\Visitor\SerializationVisitorInterface;
8use JMS\Serializer\XmlSerializationVisitor;
9
10/**
11 * @author Asmir Mustafic <goetas@gmail.com>
12 */
13final class XmlSerializationVisitorFactory implements SerializationVisitorFactory
14{
15    /**
16     * @var string
17     */
18    private $defaultRootName = 'result';
19
20    /**
21     * @var string
22     */
23    private $defaultVersion = '1.0';
24
25    /**
26     * @var string
27     */
28    private $defaultEncoding = 'UTF-8';
29
30    /**
31     * @var bool
32     */
33    private $formatOutput = true;
34
35    /**
36     * @var string|null
37     */
38    private $defaultRootNamespace;
39
40    public function getVisitor(): SerializationVisitorInterface
41    {
42        return new XmlSerializationVisitor(
43            $this->formatOutput,
44            $this->defaultEncoding,
45            $this->defaultVersion,
46            $this->defaultRootName,
47            $this->defaultRootNamespace
48        );
49    }
50
51    public function setDefaultRootName(string $name, ?string $namespace = null): self
52    {
53        $this->defaultRootName = $name;
54        $this->defaultRootNamespace = $namespace;
55        return $this;
56    }
57
58    public function setDefaultVersion(string $version): self
59    {
60        $this->defaultVersion = $version;
61        return $this;
62    }
63
64    public function setDefaultEncoding(string $encoding): self
65    {
66        $this->defaultEncoding = $encoding;
67        return $this;
68    }
69
70    public function setFormatOutput(bool $formatOutput): self
71    {
72        $this->formatOutput = (bool) $formatOutput;
73        return $this;
74    }
75}
76