1 | <?php |
||
12 | class Output |
||
13 | { |
||
14 | /** |
||
15 | * Is the output indented. |
||
16 | * |
||
17 | * @var boolean |
||
18 | */ |
||
19 | protected $indented = true; |
||
20 | |||
21 | /** |
||
22 | * What string is used for indentation. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $indentString = ' '; |
||
27 | |||
28 | /** |
||
29 | * Processing instructions. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $processingInstructions = []; |
||
34 | |||
35 | /** |
||
36 | * Renders the Sitemap as an XML string. |
||
37 | * |
||
38 | * @param OutputInterface $collection |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getOutput(OutputInterface $collection) |
||
43 | { |
||
44 | $xmlWriter = new XMLWriter(); |
||
45 | $xmlWriter->openMemory(); |
||
46 | $xmlWriter->setIndent($this->isIndented()); |
||
47 | $xmlWriter->startDocument('1.0', 'UTF-8'); |
||
48 | |||
49 | foreach ($this->processingInstructions as $target => $content) { |
||
50 | $xmlWriter->writePi($target, $content); |
||
51 | } |
||
52 | |||
53 | $xmlWriter->setIndentString($this->getIndentString()); |
||
54 | |||
55 | $collection->generateXML($xmlWriter); |
||
56 | |||
57 | return trim($xmlWriter->flush(true)); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Output indented? |
||
62 | * |
||
63 | * @return boolean |
||
64 | */ |
||
65 | public function isIndented() |
||
69 | |||
70 | /** |
||
71 | * Indent the output? |
||
72 | * |
||
73 | * @param boolean $indented |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function setIndented($indented) |
||
83 | |||
84 | /** |
||
85 | * String used for indentation. |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getIndentString() |
||
93 | |||
94 | /** |
||
95 | * Set the string used for indentation. |
||
96 | * |
||
97 | * @param string $indentString |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setIndentString($indentString) |
||
107 | |||
108 | /** |
||
109 | * Adds a processing instruction. |
||
110 | * |
||
111 | * @param string $target |
||
112 | * @param string $content |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | public function addProcessingInstruction($target, $content) |
||
122 | } |
||
123 |