Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Spatie\ArrayToXml; use DOMDocument; use DOMElement; use DOMException; use..

Decoded Output download

<?php
 namespace Spatie\ArrayToXml; use DOMDocument; use DOMElement; use DOMException; use Exception; class ArrayToXml { protected $document; protected $replaceSpacesByUnderScoresInKeyNames = true; protected $addXmlDeclaration = true; protected $numericTagNamePrefix = "numeric_"; public function __construct(array $array, $rootElement = '', $replaceSpacesByUnderScoresInKeyNames = true, $xmlEncoding = null, $xmlVersion = "1.0", $domProperties = array(), $xmlStandalone = null) { $this->document = new DOMDocument($xmlVersion, $xmlEncoding ?? ''); if (!is_null($xmlStandalone)) { $this->document->xmlStandalone = $xmlStandalone; } if (!empty($domProperties)) { $this->setDomProperties($domProperties); } $this->replaceSpacesByUnderScoresInKeyNames = $replaceSpacesByUnderScoresInKeyNames; if (!empty($array) && $this->isArrayAllKeySequential($array)) { throw new DOMException("Invalid Character Error"); } $root = $this->createRootElement($rootElement); $this->document->appendChild($root); $this->convertElement($root, $array); } public function setNumericTagNamePrefix(string $prefix) { $this->numericTagNamePrefix = $prefix; } public static function convert(array $array, $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = null, string $xmlVersion = "1.0", array $domProperties = array(), bool $xmlStandalone = null) { $converter = new static($array, $rootElement, $replaceSpacesByUnderScoresInKeyNames, $xmlEncoding, $xmlVersion, $domProperties, $xmlStandalone); return $converter->toXml(); } public function toXml() : string { return $this->addXmlDeclaration ? $this->document->saveXML() : $this->document->saveXml($this->document->documentElement); } public function toDom() : DOMDocument { return $this->document; } protected function ensureValidDomProperties(array $domProperties) { foreach ($domProperties as $key => $value) { if (!property_exists($this->document, $key)) { throw new Exception("{$key} is not a valid property of DOMDocument"); } } } public function setDomProperties(array $domProperties) { $this->ensureValidDomProperties($domProperties); foreach ($domProperties as $key => $value) { $this->document->{$key} = $value; } return $this; } public function prettify() { $this->document->preserveWhiteSpace = false; $this->document->formatOutput = true; return $this; } public function dropXmlDeclaration() { $this->addXmlDeclaration = false; return $this; } public function addProcessingInstruction($target, $data) { $elements = $this->document->getElementsByTagName("*"); $rootElement = $elements->count() > 0 ? $elements->item(0) : null; $processingInstruction = $this->document->createProcessingInstruction($target, $data); $this->document->insertBefore($processingInstruction, $rootElement); return $this; } private function convertElement(DOMElement $element, $value) { $sequential = $this->isArrayAllKeySequential($value); if (!is_array($value)) { $value = htmlspecialchars($value ?? ''); $value = $this->removeControlCharacters($value); $element->nodeValue = $value; return; } foreach ($value as $key => $data) { if (!$sequential) { if ($key === "_attributes" || $key === "@attributes") { $this->addAttributes($element, $data); } elseif (($key === "_value" || $key === "@value") && is_string($data)) { $element->nodeValue = htmlspecialchars($data); } elseif (($key === "_cdata" || $key === "@cdata") && is_string($data)) { $element->appendChild($this->document->createCDATASection($data)); } elseif (($key === "_mixed" || $key === "@mixed") && is_string($data)) { $fragment = $this->document->createDocumentFragment(); $fragment->appendXML($data); $element->appendChild($fragment); } elseif ($key === "__numeric") { $this->addNumericNode($element, $data); } elseif (substr($key, 0, 9) === "__custom:") { $this->addNode($element, str_replace("\:", ":", preg_split("/(?<!\):/", $key)[1]), $data); } else { $this->addNode($element, $key, $data); } } elseif (is_array($data)) { $this->addCollectionNode($element, $data); } else { $this->addSequentialNode($element, $data); } } } protected function addNumericNode(DOMElement $element, $value) { foreach ($value as $key => $item) { $this->convertElement($element, array($this->numericTagNamePrefix . $key => $item)); } } protected function addNode(DOMElement $element, $key, $value) { if ($this->replaceSpacesByUnderScoresInKeyNames) { $key = str_replace(" ", "_", $key); } $child = $this->document->createElement($key); $element->appendChild($child); $this->convertElement($child, $value); } protected function addCollectionNode(DOMElement $element, $value) { if ($element->childNodes->length === 0 && $element->attributes->length === 0) { $this->convertElement($element, $value); return; } $child = $this->document->createElement($element->tagName); $element->parentNode->appendChild($child); $this->convertElement($child, $value); } protected function addSequentialNode(DOMElement $element, $value) { if (empty($element->nodeValue) && !is_numeric($element->nodeValue)) { $element->nodeValue = htmlspecialchars($value); return; } $child = $this->document->createElement($element->tagName); $child->nodeValue = htmlspecialchars($value); $element->parentNode->appendChild($child); } protected function isArrayAllKeySequential($value) { if (!is_array($value)) { return false; } if (count($value) <= 0) { return true; } if (\key($value) === "__numeric") { return false; } return array_unique(array_map("is_int", array_keys($value))) === array(true); } protected function addAttributes(DOMElement $element, array $data) { foreach ($data as $attrKey => $attrVal) { $element->setAttribute($attrKey, $attrVal ?? ''); } } protected function createRootElement($rootElement) : DOMElement { if (is_string($rootElement)) { $rootElementName = $rootElement ?: "root"; return $this->document->createElement($rootElementName); } $rootElementName = $rootElement["rootElementName"] ?? "root"; $element = $this->document->createElement($rootElementName); foreach ($rootElement as $key => $value) { if ($key !== "_attributes" && $key !== "@attributes") { continue; } $this->addAttributes($element, $rootElement[$key]); } return $element; } protected function removeControlCharacters(string $value) : string { return preg_replace("/[-	-]/", '', $value); } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Spatie\ArrayToXml; use DOMDocument; use DOMElement; use DOMException; use Exception; class ArrayToXml { protected $document; protected $replaceSpacesByUnderScoresInKeyNames = true; protected $addXmlDeclaration = true; protected $numericTagNamePrefix = "\156\165\x6d\x65\162\151\143\x5f"; public function __construct(array $array, $rootElement = '', $replaceSpacesByUnderScoresInKeyNames = true, $xmlEncoding = null, $xmlVersion = "\x31\56\60", $domProperties = array(), $xmlStandalone = null) { $this->document = new DOMDocument($xmlVersion, $xmlEncoding ?? ''); if (!is_null($xmlStandalone)) { $this->document->xmlStandalone = $xmlStandalone; } if (!empty($domProperties)) { $this->setDomProperties($domProperties); } $this->replaceSpacesByUnderScoresInKeyNames = $replaceSpacesByUnderScoresInKeyNames; if (!empty($array) && $this->isArrayAllKeySequential($array)) { throw new DOMException("\111\156\x76\141\154\151\x64\x20\103\x68\141\x72\x61\143\164\x65\162\x20\105\162\x72\157\162"); } $root = $this->createRootElement($rootElement); $this->document->appendChild($root); $this->convertElement($root, $array); } public function setNumericTagNamePrefix(string $prefix) { $this->numericTagNamePrefix = $prefix; } public static function convert(array $array, $rootElement = '', bool $replaceSpacesByUnderScoresInKeyNames = true, string $xmlEncoding = null, string $xmlVersion = "\x31\56\x30", array $domProperties = array(), bool $xmlStandalone = null) { $converter = new static($array, $rootElement, $replaceSpacesByUnderScoresInKeyNames, $xmlEncoding, $xmlVersion, $domProperties, $xmlStandalone); return $converter->toXml(); } public function toXml() : string { return $this->addXmlDeclaration ? $this->document->saveXML() : $this->document->saveXml($this->document->documentElement); } public function toDom() : DOMDocument { return $this->document; } protected function ensureValidDomProperties(array $domProperties) { foreach ($domProperties as $key => $value) { if (!property_exists($this->document, $key)) { throw new Exception("{$key}\40\151\163\x20\156\x6f\164\x20\x61\40\166\x61\x6c\151\x64\x20\x70\x72\157\x70\145\162\164\x79\40\157\146\40\x44\x4f\x4d\x44\x6f\143\165\155\x65\x6e\x74"); } } } public function setDomProperties(array $domProperties) { $this->ensureValidDomProperties($domProperties); foreach ($domProperties as $key => $value) { $this->document->{$key} = $value; } return $this; } public function prettify() { $this->document->preserveWhiteSpace = false; $this->document->formatOutput = true; return $this; } public function dropXmlDeclaration() { $this->addXmlDeclaration = false; return $this; } public function addProcessingInstruction($target, $data) { $elements = $this->document->getElementsByTagName("\52"); $rootElement = $elements->count() > 0 ? $elements->item(0) : null; $processingInstruction = $this->document->createProcessingInstruction($target, $data); $this->document->insertBefore($processingInstruction, $rootElement); return $this; } private function convertElement(DOMElement $element, $value) { $sequential = $this->isArrayAllKeySequential($value); if (!is_array($value)) { $value = htmlspecialchars($value ?? ''); $value = $this->removeControlCharacters($value); $element->nodeValue = $value; return; } foreach ($value as $key => $data) { if (!$sequential) { if ($key === "\x5f\141\164\x74\x72\151\x62\165\x74\x65\x73" || $key === "\100\141\x74\164\162\x69\x62\x75\x74\x65\163") { $this->addAttributes($element, $data); } elseif (($key === "\137\166\141\x6c\165\145" || $key === "\100\x76\141\x6c\165\x65") && is_string($data)) { $element->nodeValue = htmlspecialchars($data); } elseif (($key === "\137\143\x64\x61\164\141" || $key === "\x40\143\144\x61\164\141") && is_string($data)) { $element->appendChild($this->document->createCDATASection($data)); } elseif (($key === "\137\155\x69\170\145\x64" || $key === "\x40\155\x69\x78\145\144") && is_string($data)) { $fragment = $this->document->createDocumentFragment(); $fragment->appendXML($data); $element->appendChild($fragment); } elseif ($key === "\137\x5f\x6e\165\155\145\162\x69\143") { $this->addNumericNode($element, $data); } elseif (substr($key, 0, 9) === "\137\137\x63\x75\163\164\157\155\x3a") { $this->addNode($element, str_replace("\x5c\x3a", "\x3a", preg_split("\x2f\50\77\x3c\41\x5c\x5c\x29\72\x2f", $key)[1]), $data); } else { $this->addNode($element, $key, $data); } } elseif (is_array($data)) { $this->addCollectionNode($element, $data); } else { $this->addSequentialNode($element, $data); } } } protected function addNumericNode(DOMElement $element, $value) { foreach ($value as $key => $item) { $this->convertElement($element, array($this->numericTagNamePrefix . $key => $item)); } } protected function addNode(DOMElement $element, $key, $value) { if ($this->replaceSpacesByUnderScoresInKeyNames) { $key = str_replace("\x20", "\x5f", $key); } $child = $this->document->createElement($key); $element->appendChild($child); $this->convertElement($child, $value); } protected function addCollectionNode(DOMElement $element, $value) { if ($element->childNodes->length === 0 && $element->attributes->length === 0) { $this->convertElement($element, $value); return; } $child = $this->document->createElement($element->tagName); $element->parentNode->appendChild($child); $this->convertElement($child, $value); } protected function addSequentialNode(DOMElement $element, $value) { if (empty($element->nodeValue) && !is_numeric($element->nodeValue)) { $element->nodeValue = htmlspecialchars($value); return; } $child = $this->document->createElement($element->tagName); $child->nodeValue = htmlspecialchars($value); $element->parentNode->appendChild($child); } protected function isArrayAllKeySequential($value) { if (!is_array($value)) { return false; } if (count($value) <= 0) { return true; } if (\key($value) === "\137\x5f\156\165\155\145\162\x69\x63") { return false; } return array_unique(array_map("\x69\x73\137\151\156\x74", array_keys($value))) === array(true); } protected function addAttributes(DOMElement $element, array $data) { foreach ($data as $attrKey => $attrVal) { $element->setAttribute($attrKey, $attrVal ?? ''); } } protected function createRootElement($rootElement) : DOMElement { if (is_string($rootElement)) { $rootElementName = $rootElement ?: "\162\x6f\x6f\x74"; return $this->document->createElement($rootElementName); } $rootElementName = $rootElement["\x72\x6f\x6f\164\x45\154\x65\x6d\145\x6e\x74\x4e\141\x6d\x65"] ?? "\x72\157\x6f\x74"; $element = $this->document->createElement($rootElementName); foreach ($rootElement as $key => $value) { if ($key !== "\x5f\141\x74\164\x72\151\142\165\x74\x65\163" && $key !== "\100\x61\x74\164\162\151\x62\165\164\x65\x73") { continue; } $this->addAttributes($element, $rootElement[$key]); } return $element; } protected function removeControlCharacters(string $value) : string { return preg_replace("\x2f\133\x5c\x78\60\60\55\134\x78\x30\x39\x5c\x78\60\x42\x5c\x78\x30\x43\x5c\x78\x30\105\x2d\134\170\61\x46\134\170\67\106\x5d\57", '', $value); } }

Function Calls

None

Variables

None

Stats

MD5 921068048bc4cdf48f4adea20d2a329e
Eval Count 0
Decode Time 90 ms