Ejemplo n.º 1
0
 protected function fixViaState($content, StateBag $state_bag, $state_name, $open_regexp, $close_regexp, $open_replacement, $close_replacement)
 {
     $stored_sibling = $state_bag->getSiblingNode($state_name);
     // If no stored open quote node & open quote detected
     if ($stored_sibling === false && preg_match($open_regexp, $content)) {
         // Store the current node
         $state_bag->storeSiblingNode($state_name);
         // If we have a open sibling and we detect a closing quote
     } elseif ($stored_sibling instanceof StateNode && preg_match($close_regexp, $content)) {
         // Replace the closing tag
         $content = preg_replace($close_regexp, "\$1" . $close_replacement . '$2', $content, 1);
         // Replace the opening tag
         $open_content = preg_replace($open_regexp, "\$1" . $open_replacement . '$2', $stored_sibling->getNode()->wholeText, 1);
         $state_bag->fixSiblingNode($state_name, $open_content);
     }
     return $content;
 }
Ejemplo n.º 2
0
 /**
  * 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);
     }
 }