1 | <?php |
||
12 | final class FixedQuotation implements QuotationInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $headerText; |
||
18 | |||
19 | /** |
||
20 | * @param string $headerText |
||
21 | */ |
||
22 | 15 | public function __construct(string $headerText = '%s (%s):') |
|
26 | |||
27 | /** |
||
28 | * @param MessageBodyCollection $body |
||
29 | * @param MessageInterface $originalMessage |
||
30 | * @return MessageBodyCollection |
||
31 | * @throws \DOMException |
||
32 | */ |
||
33 | 15 | public function quote(MessageBodyCollection $body, MessageInterface $originalMessage): MessageBodyCollection |
|
80 | |||
81 | /** |
||
82 | * @param string $newHtml |
||
83 | * @param string $originalHtml |
||
84 | * @param string $headerText |
||
85 | * @return string |
||
86 | * @throws \DOMException |
||
87 | */ |
||
88 | 15 | private function quoteHtml(string $newHtml, string $originalHtml, string $headerText): string |
|
160 | |||
161 | /** |
||
162 | * @param \DOMDocument $document |
||
163 | * @return \DOMElement |
||
164 | */ |
||
165 | 13 | private function prepareBody(\DOMDocument $document): \DOMElement |
|
166 | { |
||
167 | 13 | if (!$document->documentElement) { |
|
168 | throw new \UnexpectedValueException('Cannot prepare empty document'); |
||
169 | } |
||
170 | |||
171 | 13 | $bodyList = $document->getElementsByTagName('body'); |
|
172 | 13 | if ($bodyList->length === 0) { |
|
173 | $html = $document->createElement('html'); |
||
174 | $body = $document->createElement('body'); |
||
175 | $html->appendChild($body); |
||
176 | $body->appendChild($document->documentElement); |
||
177 | if ($document->documentElement instanceof \DOMElement) { |
||
178 | $document->removeChild($document->documentElement); |
||
179 | } |
||
180 | $document->appendChild($html); |
||
181 | return $body; |
||
182 | } |
||
183 | |||
184 | /** @var \DOMElement $body */ |
||
185 | 13 | $body = $bodyList->item(0); |
|
186 | |||
187 | 13 | $queryHtml = new \DOMXPath($document); |
|
188 | 13 | $htmlTags = $queryHtml->query('//html'); |
|
189 | 13 | if ($htmlTags && $htmlTags->length > 0) { |
|
190 | /** @var \DOMElement $html */ |
||
191 | 13 | $html = $htmlTags->item(0); |
|
192 | 13 | $html->appendChild($body); |
|
193 | 13 | $document->removeChild($document->documentElement); |
|
194 | 13 | $document->appendChild($html); |
|
195 | 13 | return $body; |
|
196 | } |
||
197 | |||
198 | $html = $document->createElement('html'); |
||
199 | $html->appendChild($body); |
||
200 | $document->removeChild($document->documentElement); |
||
201 | $document->appendChild($html); |
||
202 | return $body; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * @param AlternativeText $newText |
||
207 | * @param AlternativeText $originalText |
||
208 | * @param string $headerText |
||
209 | * @return AlternativeText |
||
210 | */ |
||
211 | 15 | private function quoteText( |
|
225 | } |
||
226 |