Merge attributes from the given node to this one

@param \rampage\core\xml\SimpleXmlElement $node
@param bool $replace
978368
public function mergeAttributes(SimpleXmlElement $node, $replace = true)
    {
        foreach ($node->attributes() as $name => $value) {
            if (isset($this[$name])) {
                if ($replace) {
                    $this[$name] = (string)$value;
                }

                continue;
            }

            $this->addAttribute($name, (string)$value);
        }

        return $this;
    }
714494
public function replaceWith(Element $element) 
	{
		// if the element has a parent
		if ( ! empty($this->parent)) {
			$this->parent->replaceChild($this, $element);
		} else {
			throw new \BadMethodCallException(
				__METHOD__."() expects this element to have a parent element"
			);
		}
		
		return $this;
	}
40267
public function replaceWith($nodes) {
    $first = TRUE;
    foreach ($this->nodes as $node) {
      if (!$first) {
        if (is_array($nodes)) {
          $nodes = new NodeCollection($nodes, FALSE);
        }
        $nodes = clone $nodes;
      }
      $node->replaceWith($nodes);
      $first = FALSE;
    }
    return $this;
  }
256732
public void replaceWith(HasNode node) {
		feature = node.feature;
		nodeName = node.nodeName;
		trueNode = node.trueNode;
		falseNode = node.falseNode;
	}
1356257
protected function addChanges(SimpleXMLElement $releaseNode, Release $release)
	{
		$changesNode = $releaseNode->addChild('changes');

		foreach ($release->getAllChanges() as $type => $changes)
		{
			$typeNode = $changesNode->addChild('type');
			$typeNode->addAttribute('name', $type);

			foreach ($changes as $change)
			{
				$typeNode->addChild('change', $change);
			}
		}
	}
1007366
public function send($replace = true)
    {
        if (headers_sent()) {
            return;
        }

        foreach ($this->headers as $header) {
            header($header, $replace);
        }

        return $this;
    }
383345
public function merge(ServerNodeInterface $serverNode)
    {

        // append the certificate nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\CertificateNode $certificate */
        foreach ($serverNode->getCertificates() as $certificate) {
            $this->certificates[] = $certificate;
        }

        // append the virtual host nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\VirtualHostNode $virtualHost */
        foreach ($serverNode->getVirtualHosts() as $virtualHost) {
            $this->virtualHosts[] = $virtualHost;
        }

        // append the location nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\LocationNode $location */
        foreach ($serverNode->getLocations() as $location) {
            $this->locations[] = $location;
        }

        // append the environment variable nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\EnvironmentVariableNode $environmentVariable */
        foreach ($serverNode->getEnvironmentVariables() as $environmentVariable) {
            $this->environmentVariables[] = $environmentVariable;
        }

        // append the rewrite nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\RewriteNode $rewrite */
        foreach ($serverNode->getRewrites() as $rewrite) {
            $this->rewrites[] = $rewrite;
        }

        // append the access nodes found in the passed server node
        /** @var \AppserverIo\Appserver\Core\Api\Node\AccessNode $access */
        foreach ($serverNode->getAccesses() as $access) {
            $this->accesses[] = $access;
        }
    }
647873
protected function _merge($domNew, $dom)
    {
        $xPath = new DOMXPath($dom);
        $this->_mergeNodes($dom->documentElement, $domNew->documentElement, $xPath, $dom, '/OX');
    }
834951
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);
        }
    }
600848
private function replaceElementsWithPara(Element $node): ?self {
        // Check to see if the node no longer exist.
        // 'Ghost' nodes have their ownerDocument property set to null - will throw a warning on access.
        // Use another common property with isset() - won't throw any warnings.
        if (!isset($node->nodeName)) {
            return null;
        }

        $newEl = $this->document()->createElement('p');

        $newEl->append($node->contents()->detach());

        foreach ($node->attributes as $attr) {
            $newEl->attr($attr->localName, $attr->nodeValue);
        }

        $node->replaceWith($newEl);

        return $this;
    }
519276
public function append(Node $node)
    {

        if (!is_array($this->_children)) {
            $this->_children = [];
        }

        $this->_children[] = $node;
        return $this;
    }
709949
protected function normalizeNode(DOMNode $node)
	{
		if (!$node->parentNode)
		{
			// Ignore nodes that have been removed from the document
			return;
		}
		if ($node instanceof DOMElement)
		{
			$this->normalizeElement($node);
		}
		elseif ($node instanceof DOMAttr)
		{
			$this->normalizeAttribute($node);
		}
	}
277399
protected function pushChildNode(Element $node)
    {
        if ($node->hasChildNodes()) {
            if ($node->childNodes->first() instanceof Link) {

                $parseUrl = parse_url($node->childNodes->first()->getAttributeHref());
                $parseUrlQuery = [];

                if (isset($parseUrl[ 'query' ])) {
                    parse_str($parseUrl[ 'query' ], $parseUrlQuery);
                }

                if (isset($parseUrlQuery[ 'page' ])) {
                    if (input()->get('page') === $parseUrlQuery[ 'page' ]) {
                        $node->attributes->addAttributeClass('active');
                        $node->childNodes->first()->attributes->addAttributeClass('active');
                    }
                } else {
                    $hrefUriSegments = [];

                    if (isset($parseUrl[ 'path' ])) {
                        $hrefUriSegments = (new Uri\Segments($parseUrl[ 'path' ]))->getParts();
                    }

                    $currentUriSegments = server_request()->getUri()->getSegments()->getParts();

                    $matchSegments = array_slice($currentUriSegments, 0, count($hrefUriSegments));

                    $stringHrefSegments = implode('/', $hrefUriSegments);
                    $stringMatchSegments = implode('/', $matchSegments);

                    if ($stringHrefSegments === $stringMatchSegments) {
                        $node->attributes->addAttributeClass('active');
                        $node->childNodes->first()->attributes->addAttributeClass('active');
                    }
                }
            }
        }

        $this->childNodes->push($node);
    }
974110
protected function mergeBranches(array $nodes)
	{
		$sortedNodes = [];
		foreach ($nodes as $node)
		{
			$outerXML = $node->ownerDocument->saveXML($node);
			$innerXML = preg_replace('([^>]+>(.*)<[^<]+)s', '$1', $outerXML);

			$sortedNodes[$innerXML][] = $node;
		}

		foreach ($sortedNodes as $identicalNodes)
		{
			if (count($identicalNodes) < 2)
			{
				continue;
			}

			$expr = [];
			foreach ($identicalNodes as $i => $node)
			{
				$expr[] = $node->getAttribute('test');

				if ($i > 0)
				{
					$node->parentNode->removeChild($node);
				}
			}

			$identicalNodes[0]->setAttribute('test', implode(' or ', $expr));
		}
	}
1234562
public static function remove_node($node) {
		if (
			! \is_a($node, 'DOMElement') &&
			! \is_a($node, 'DOMNode')
		) {
			return false;
		}

		$node->parentNode->removeChild($node);

		return true;
	}
468061
public static function replaceTag($tag, $replacement, $content, $attributes = null)
        {
            $content = preg_replace("/<{$tag}.*?>/", "<{$replacement} {$attributes}>", $content);
            $content = preg_replace("/<\/{$tag}>/", "</{$replacement}>", $content);
            return $content;
        }
124245
public function mutate(Node $node)
    {
        return new Node\Expr\AssignOp\Mul($node->var, $node->expr, $node->getAttributes());
    }