protected function replaceCallback(\DOMNode $node)
    {
        return function ($text) use ($node) {
            $attribute = '';
            if ($node instanceof \DOMText) {
                $attribute = 'nodeValue';
            } elseif ($node instanceof \DOMAttr) {
                $attribute = 'value';
            }

            if ($attribute === '') {
                throw new ParserCrawlerAfterListenerException('No callback behavior set for this node type.');
            }

            // reserved character in XML: &
            $text = str_replace('&amp;', '&', $text);
            $text = str_replace('&', '&amp;', $text);
            $text = str_replace('&lt;', '<', $text);
            $text = str_replace('&gt;', '>', $text);

            $node->$attribute = $text;
        };
    }
protected function replaceCallback(\DOMNode $node)
    {
        return function ($text) use ($node) {
            $attribute = '';
            if ($node instanceof \DOMText) {
                $attribute = 'nodeValue';
            } elseif ($node instanceof \DOMAttr) {
                $attribute = 'value';
            }

            if ($attribute === '') {
                throw new ParserCrawlerAfterListenerException('No callback behavior set for this node type.');
            }

            // reserved character in XML: &
            $text = str_replace('&amp;', '&', $text);
            $text = str_replace('&', '&amp;', $text);
            $text = str_replace('&lt;', '<', $text);
            $text = str_replace('&gt;', '>', $text);

            $node->$attribute = $text;
        };
    }
protected function replaceCallback ( \ DOMNode $ node ) { return function ( $ text ) use ( $ node ) { $ attribute = '' ; if ( $ node instanceof \ DOMText ) { $ attribute = 'nodeValue' ; } elseif ( $ node instanceof \ DOMAttr ) { $ attribute = 'value' ; } if ( $ attribute === '' ) { throw new ParserCrawlerAfterListenerException ( 'No callback behavior set for this node type.' ) ; } // reserved character in XML: & $ text = str_replace ( '&amp;' , '&' , $ text ) ; $ text = str_replace ( '&' , '&amp;' , $ text ) ; $ text = str_replace ( '&lt;' , '<' , $ text ) ; $ text = str_replace ( '&gt;' , '>' , $ text ) ; $ node -> $ attribute = $ text ; } ; }
Callback used to replace text with translated version

@param \DOMNode $node
@return callable
Callback used to replace text with translated version