/** * Run the Fixers on a DOMText content. * * @param \DOMText $childNode The node to fix * @param \DOMNode $node The parent node where to replace the current one * @param \DOMDocument $dom The Document */ private function doFix(\DOMText $childNode, \DOMNode $node, \DOMDocument $dom) { $content = $childNode->wholeText; $current_node = new StateNode($childNode, $node, $dom); $this->stateBag->setCurrentNode($current_node); // run the string on all the fixers foreach ($this->_rules as $fixer) { $content = $fixer->fix($content, $this->stateBag); } // update the DOM only if the node has changed if ($childNode->wholeText !== $content) { $new_node = $dom->createTextNode($content); $node->replaceChild($new_node, $childNode); // As the node is replaced, we also update it in the StateNode $current_node->replaceNode($new_node); } }