1 | <?php declare(strict_types=1); |
||
27 | class XmlFormatter implements FormatterInterface |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * @var XmlAbstract |
||
32 | */ |
||
33 | protected $standard; |
||
34 | |||
35 | /** |
||
36 | * @param XmlAbstract $standard |
||
37 | */ |
||
38 | 8 | public function __construct(XmlAbstract $standard) |
|
42 | |||
43 | /** |
||
44 | * @param \DOMDocument $document |
||
45 | * @param FeedInterface $feed |
||
46 | * @return XmlFormatter |
||
47 | */ |
||
48 | 4 | public function setHeaders(\DOMDocument $document, FeedInterface $feed) : XmlFormatter |
|
56 | |||
57 | /** |
||
58 | * @param \DOMDocument $document |
||
59 | * @param NodeInterface $node |
||
60 | * @return XmlFormatter |
||
61 | */ |
||
62 | 3 | public function addItem(\DOMDocument $document, NodeInterface $node) : XmlFormatter |
|
72 | |||
73 | /** |
||
74 | * @param RuleSet $ruleSet |
||
75 | * @param \DOMDocument $document |
||
76 | * @param \DOMElement $rootElement |
||
77 | * @param NodeInterface $node |
||
78 | */ |
||
79 | 5 | public function buildElements(RuleSet $ruleSet, \DOMDocument $document, \DOMElement $rootElement, NodeInterface $node) : void |
|
80 | { |
||
81 | 5 | $rules = $this->getAllRules($ruleSet, $node); |
|
82 | |||
83 | 5 | foreach ($rules as $rule) { |
|
84 | 5 | $rule->apply($document, $rootElement, $node); |
|
85 | } |
||
86 | 5 | } |
|
87 | |||
88 | /** |
||
89 | * @param RuleSet $ruleSet |
||
90 | * @param NodeInterface $node |
||
91 | * @return iterable |
||
92 | */ |
||
93 | 6 | public function getAllRules(RuleSet $ruleSet, NodeInterface $node) : iterable |
|
103 | |||
104 | /** |
||
105 | * @return \DOMDocument |
||
106 | */ |
||
107 | 7 | public function getEmptyDocument() : \DOMDocument |
|
111 | |||
112 | /** |
||
113 | * @return \DOMDocument |
||
114 | */ |
||
115 | 6 | public function getDocument() : \DOMDocument |
|
121 | |||
122 | /** |
||
123 | * @param FeedInterface $feed |
||
124 | * @return string |
||
125 | */ |
||
126 | 3 | public function toString(FeedInterface $feed) : string |
|
132 | |||
133 | /** |
||
134 | * @param FeedInterface $feed |
||
135 | * @return \DomDocument |
||
136 | */ |
||
137 | 4 | public function toDom(FeedInterface $feed) : \DOMDocument |
|
147 | |||
148 | 4 | public function setNS(\DOMDocument $document, FeedInterface $feed) |
|
149 | { |
||
150 | 4 | $firstChild = $document->firstChild; |
|
151 | 4 | foreach ($feed->getNS() as $namespace => $dtd) { |
|
152 | $firstChild->setAttributeNS( |
||
153 | 'http://www.w3.org/2000/xmlns/', // xmlns namespace URI |
||
154 | 'xmlns:'.$namespace, |
||
155 | $dtd |
||
156 | ); |
||
157 | } |
||
158 | 4 | } |
|
159 | |||
160 | /** |
||
161 | * @param \DOMDocument $document |
||
162 | * @param FeedInterface $feed |
||
163 | * @return XmlFormatter |
||
164 | */ |
||
165 | 5 | public function setItems(\DOMDocument $document, FeedInterface $feed) : XmlFormatter |
|
173 | } |
||
174 |