24 private $validationState;
87 $this->validationState = $validationState;
88 $this->schema = $schema;
102 return in_array($attributeName, $this->idAttributes);
113 foreach ($this->contextXPath as $context) {
114 if (strpos($xPath, $context) === 0) {
129 return count(array_intersect($xPath, $this->contextXPath)) === count($xPath);
155 $currentXPath = $node->getNodePath();
156 if ($node->parentNode !==
null && !$node->isSameNode($node->parentNode)) {
157 $parentXPath = $this->
createXPath($node->parentNode);
158 $pathParts = explode(
'/', $currentXPath);
159 $currentXPath =
'/' . end($pathParts);
161 $attributesXPath =
'';
162 if ($node->hasAttributes()) {
171 if (substr($currentXPath, -1) ===
']') {
172 $currentXPath = substr($currentXPath, 0, strrpos($currentXPath,
'['));
174 $attributesXPath =
'[' . implode(
' and ',
$attributes) .
']';
177 return '/' . trim($parentXPath . $currentXPath . $attributesXPath,
'/');
191 protected function nestedMerge(\DOMXPath $rootDomXPath, \DOMNodeList $insertedNodes, \DOMNode $contextNode)
193 for (
$i = 0, $iLength = $insertedNodes->length;
$i < $iLength; ++
$i) {
194 $insertedItem = $insertedNodes->item(
$i);
195 switch ($insertedItem->nodeType) {
197 case XML_COMMENT_NODE:
198 case XML_CDATA_SECTION_NODE:
199 if (trim($insertedItem->textContent) !==
'') {
204 $insertedXPath = $this->
createXPath($insertedItem);
205 $rootMatchList = $rootDomXPath->query($insertedXPath, $contextNode);
206 $jLength = $rootMatchList->length;
208 for ($j = 0; $j < $jLength; ++$j) {
209 $rootItem = $rootMatchList->item($j);
213 $rootItem->nodeValue = $insertedItem->nodeValue;
218 if ($this->isMergeSimpleXMLElement) {
219 $this->
nestedMerge($rootDomXPath, $insertedItem->childNodes, $rootItem);
225 $this->
nestedMerge($rootDomXPath, $insertedItem->childNodes, $rootItem);
247 protected function appendChild(\DOMNode $parentNode, \DOMNode $childNode)
249 $importNode = $this->
getDom()->importNode($childNode,
true);
250 $parentNode->appendChild($importNode);
260 protected function insertBefore(\DOMNode $parentNode, \DOMNode $childNode)
262 $importNode = $this->
getDom()->importNode($childNode,
true);
263 $parentNode->insertBefore($importNode);
274 return $node->childNodes->length == 1 && $node->childNodes->item(0) instanceof \DOMText;
286 if (!$node->hasAttributes()) {
291 if (in_array(
$name, $this->idAttributes)) {
313 $parentDoom = $this->
getDom();
314 $this->
nestedMerge(
new \DOMXPath($parentDoom), $node->childNodes, $parentDoom->documentElement);
328 if ($this->validationState->isValidationRequired() && $this->schema) {
331 throw new \Magento\Framework\Exception\LocalizedException(
350 $schema = $schema !==
null ? $schema : $this->schema;
351 libxml_use_internal_errors(
true);
354 }
catch (\Exception $exception) {
355 libxml_use_internal_errors(
false);
358 libxml_use_internal_errors(
false);
372 $result = static::ERROR_FORMAT_DEFAULT;
373 foreach ($errorInfo as $field =>
$value) {
376 if (strpos(
$result,
'%') !==
false) {
377 throw new \Magento\Framework\Exception\LocalizedException(
379 'Error format "' . static::ERROR_FORMAT_DEFAULT .
'" contains unsupported placeholders.' 395 if (!isset($this->domDocument)) {
410 if (!isset($this->domDocument)) {
411 throw new \Magento\Framework\Exception\LocalizedException(
412 new \
Magento\Framework\
Phrase(
'Object DOMDocument should be created.')
437 unset($this->domDocument);
448 if (!$this->validationState->isValidationRequired()) {
elseif(isset( $params[ 'redirect_parent']))
static validateDomDocument(\DOMDocument $dom, $schema, $errorFormat=self::ERROR_FORMAT_DEFAULT)
createXPath(\DOMNode $node)
appendChild(\DOMNode $parentNode, \DOMNode $childNode)
renderErrorMessage(\LibXMLError $errorInfo)
setDom(\DOMDocument $domDocument)
nestedMerge(\DOMXPath $rootDomXPath, \DOMNodeList $insertedNodes, \DOMNode $contextNode)
mergeNode(\DOMElement $node)
isContextXPath(array $xPath)
mergeAttributes(\DOMElement $baseNode, \DOMNode $mergeNode)
const ERROR_FORMAT_DEFAULT
isIdAttribute($attributeName)
__construct(ValidationStateInterface $validationState, $schema, $isMergeSimpleXMLElement=false, array $contextXPath=[], array $idAttributes=[])
isTextNode(\DOMNode $node)
hasIdAttribute(\DOMNode $node)
insertBefore(\DOMNode $parentNode, \DOMNode $childNode)
validateDomDocument(\DOMDocument $domDocument, $schema=null)
validate($schemaFilePath=null)
if(!isset($_GET['name'])) $name