@@ 150-187 (lines=38) @@ | ||
147 | * |
|
148 | * @return SimpleHtmlDomInterface |
|
149 | */ |
|
150 | protected function replaceChildWithString(string $string): SimpleHtmlDomInterface |
|
151 | { |
|
152 | if (!empty($string)) { |
|
153 | $newDocument = new HtmlDomParser($string); |
|
154 | ||
155 | $tmpDomString = $this->normalizeStringForComparision($newDocument); |
|
156 | $tmpStr = $this->normalizeStringForComparision($string); |
|
157 | if ($tmpDomString !== $tmpStr) { |
|
158 | throw new \RuntimeException( |
|
159 | 'Not valid HTML fragment!' . "\n" . |
|
160 | $tmpDomString . "\n" . |
|
161 | $tmpStr |
|
162 | ); |
|
163 | } |
|
164 | } |
|
165 | ||
166 | if (\count($this->node->childNodes) > 0) { |
|
167 | foreach ($this->node->childNodes as $node) { |
|
168 | $this->node->removeChild($node); |
|
169 | } |
|
170 | } |
|
171 | ||
172 | if (!empty($newDocument)) { |
|
173 | $newDocument = $this->cleanHtmlWrapper($newDocument); |
|
174 | $ownerDocument = $this->node->ownerDocument; |
|
175 | if ( |
|
176 | $ownerDocument !== null |
|
177 | && |
|
178 | $newDocument->getDocument()->documentElement !== null |
|
179 | ) { |
|
180 | $newNode = $ownerDocument->importNode($newDocument->getDocument()->documentElement, true); |
|
181 | /** @noinspection UnusedFunctionResultInspection */ |
|
182 | $this->node->appendChild($newNode); |
|
183 | } |
|
184 | } |
|
185 | ||
186 | return $this; |
|
187 | } |
|
188 | ||
189 | /** |
|
190 | * Replace this node. |
@@ 138-174 (lines=37) @@ | ||
135 | * |
|
136 | * @return SimpleXmlDomInterface |
|
137 | */ |
|
138 | protected function replaceChildWithString(string $string): SimpleXmlDomInterface |
|
139 | { |
|
140 | if (!empty($string)) { |
|
141 | $newDocument = new XmlDomParser($string); |
|
142 | ||
143 | $tmpDomString = $this->normalizeStringForComparision($newDocument); |
|
144 | $tmpStr = $this->normalizeStringForComparision($string); |
|
145 | if ($tmpDomString !== $tmpStr) { |
|
146 | throw new \RuntimeException( |
|
147 | 'Not valid HTML fragment!' . "\n" . |
|
148 | $tmpDomString . "\n" . |
|
149 | $tmpStr |
|
150 | ); |
|
151 | } |
|
152 | } |
|
153 | ||
154 | if (\count($this->node->childNodes) > 0) { |
|
155 | foreach ($this->node->childNodes as $node) { |
|
156 | $this->node->removeChild($node); |
|
157 | } |
|
158 | } |
|
159 | ||
160 | if (!empty($newDocument)) { |
|
161 | $ownerDocument = $this->node->ownerDocument; |
|
162 | if ( |
|
163 | $ownerDocument !== null |
|
164 | && |
|
165 | $newDocument->getDocument()->documentElement !== null |
|
166 | ) { |
|
167 | $newNode = $ownerDocument->importNode($newDocument->getDocument()->documentElement, true); |
|
168 | /** @noinspection UnusedFunctionResultInspection */ |
|
169 | $this->node->appendChild($newNode); |
|
170 | } |
|
171 | } |
|
172 | ||
173 | return $this; |
|
174 | } |
|
175 | ||
176 | /** |
|
177 | * Replace this node. |