Skip to content

Commit

Permalink
Revert v2 to 2.16.0 (#200)
Browse files Browse the repository at this point in the history
This will provide a clean slate to continue v2 support.
  • Loading branch information
weirdan authored Dec 12, 2022
1 parent 3784621 commit c045b66
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/ArrayToXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class ArrayToXml

protected $numericTagNamePrefix = 'numeric_';

/**
* @param mixed[] $array
*/
public function __construct(
array $array,
$rootElement = '',
Expand Down Expand Up @@ -52,14 +49,11 @@ public function __construct(
$this->convertElement($root, $array);
}

public function setNumericTagNamePrefix(string $prefix): void
public function setNumericTagNamePrefix(string $prefix)
{
$this->numericTagNamePrefix = $prefix;
}

/**
* @param mixed[] $array
*/
public static function convert(
array $array,
$rootElement = '',
Expand All @@ -68,7 +62,7 @@ public static function convert(
string $xmlVersion = '1.0',
array $domProperties = [],
bool $xmlStandalone = null
): string {
) {
$converter = new static(
$array,
$rootElement,
Expand Down Expand Up @@ -96,7 +90,7 @@ public function toDom(): DOMDocument
return $this->document;
}

protected function ensureValidDomProperties(array $domProperties): void
protected function ensureValidDomProperties(array $domProperties)
{
foreach ($domProperties as $key => $value) {
if (! property_exists($this->document, $key)) {
Expand All @@ -105,7 +99,7 @@ protected function ensureValidDomProperties(array $domProperties): void
}
}

public function setDomProperties(array $domProperties): self
public function setDomProperties(array $domProperties)
{
$this->ensureValidDomProperties($domProperties);

Expand All @@ -116,25 +110,22 @@ public function setDomProperties(array $domProperties): self
return $this;
}

public function prettify(): self
public function prettify()
{
$this->document->preserveWhiteSpace = false;
$this->document->formatOutput = true;

return $this;
}

public function dropXmlDeclaration(): self
public function dropXmlDeclaration()
{
$this->addXmlDeclaration = false;

return $this;
}

/**
* @param mixed[]|mixed $value
*/
private function convertElement(DOMElement $element, $value): void
private function convertElement(DOMElement $element, $value)
{
$sequential = $this->isArrayAllKeySequential($value);

Expand Down Expand Up @@ -175,14 +166,14 @@ private function convertElement(DOMElement $element, $value): void
}
}

protected function addNumericNode(DOMElement $element, $value): void
protected function addNumericNode(DOMElement $element, $value)
{
foreach ($value as $key => $item) {
$this->convertElement($element, [$this->numericTagNamePrefix.$key => $item]);
}
}

protected function addNode(DOMElement $element, $key, $value): void
protected function addNode(DOMElement $element, $key, $value)
{
if ($this->replaceSpacesByUnderScoresInKeyNames) {
$key = str_replace(' ', '_', $key);
Expand All @@ -193,7 +184,7 @@ protected function addNode(DOMElement $element, $key, $value): void
$this->convertElement($child, $value);
}

protected function addCollectionNode(DOMElement $element, $value): void
protected function addCollectionNode(DOMElement $element, $value)
{
if ($element->childNodes->length === 0 && $element->attributes->length === 0) {
$this->convertElement($element, $value);
Expand All @@ -219,10 +210,6 @@ protected function addSequentialNode(DOMElement $element, $value)
$element->parentNode->appendChild($child);
}

/**
* @param mixed[] $value
* @return bool|mixed[]
*/
protected function isArrayAllKeySequential($value)
{
if (! is_array($value)) {
Expand All @@ -240,7 +227,7 @@ protected function isArrayAllKeySequential($value)
return array_unique(array_map('is_int', array_keys($value))) === [true];
}

protected function addAttributes(DOMElement $element, array $data): void
protected function addAttributes(DOMElement $element, array $data)
{
foreach ($data as $attrKey => $attrVal) {
$element->setAttribute($attrKey, $attrVal);
Expand Down

0 comments on commit c045b66

Please sign in to comment.