23 private $idAttributes = [];
40 private $schemaLocator;
56 array $idAttributes = [],
60 $this->idAttributes = array_values($idAttributes);
65 $this->schemaLocator = $schemaLocator;
77 $this->domXPath = new \DOMXPath($this->
getDom());
78 $this->nestedMerge($this->
getDom()->documentElement,
$dom->childNodes);
88 private function nestedMerge(\DOMNode $contextNode, \DOMNodeList $insertedNodes)
90 foreach ($insertedNodes as $insertedItem) {
91 switch ($insertedItem->nodeType) {
92 case XML_COMMENT_NODE:
95 case XML_CDATA_SECTION_NODE:
96 if (trim($insertedItem->textContent) !==
'') {
97 $importNode = $this->
getDom()->importNode($insertedItem,
true);
98 $contextNode->insertBefore($importNode);
102 $insertedXPath = $this->createXPath($insertedItem);
103 $rootMatchList = $this->domXPath->query($insertedXPath);
105 $jLength = $rootMatchList->length;
107 $this->processMatchedNodes($rootMatchList, $insertedItem);
109 $this->appendNode($insertedItem, $contextNode);
124 private function processMatchedNodes(\DOMNodeList $rootMatchList, \DOMElement $insertedItem)
126 foreach ($rootMatchList as $rootItem) {
128 $rootItem->nodeValue = $insertedItem->nodeValue;
130 $this->nestedMerge($rootItem, $insertedItem->childNodes);
142 private function createXPath(\DOMNode $node)
145 $currentXPath = $node->getNodePath();
146 if ($node->parentNode !==
null && !$node->isSameNode($node->parentNode)) {
147 $parentXPath = $this->createXPath($node->parentNode);
148 $pathParts = explode(
'/', $currentXPath);
149 $currentXPath =
'/' . end($pathParts);
151 $attributesXPath =
'';
152 if ($node->hasAttributes()) {
155 if (in_array(
$name, $this->idAttributes)) {
161 if (substr($currentXPath, -1) ===
']') {
162 $currentXPath = substr($currentXPath, 0, strrpos($currentXPath,
'['));
164 $attributesXPath =
'[' . implode(
' and ',
$attributes) .
']';
167 return '/' . trim($parentXPath . $currentXPath . $attributesXPath,
'/');
177 private function appendNode(\DOMNode $insertedNode, \DOMNode $contextNode)
179 $importNode = $this->
getDom()->importNode($insertedNode,
true);
181 $this->appendNodeToContext($contextNode, $importNode);
183 $contextNode->appendChild($importNode);
194 private function appendNodeToContext(\DOMNode $contextNode, \DOMNode $importNode)
196 if (!$contextNode->hasChildNodes()) {
197 $contextNode->appendChild($importNode);
200 $childContextNode =
null;
202 foreach ($contextNode->childNodes as $child) {
203 if ($child->nodeType != XML_ELEMENT_NODE) {
206 switch ($child->localName) {
208 $childContextNode = $child->nextSibling;
210 case Converter::SETTINGS_KEY:
211 $childContextNode = $child;
214 if (!$childContextNode) {
215 $childContextNode = $child;
221 $contextNode->insertBefore($importNode, $childContextNode);
__construct( $xml, ValidationStateInterface $validationState, SchemaLocatorInterface $schemaLocator, array $idAttributes=[], $typeAttributeName=null, $errorFormat=ConfigDom::ERROR_FORMAT_DEFAULT)
_mergeAttributes($baseNode, $mergeNode)
if(!isset($_GET['name'])) $name