Skip to content

Commit

Permalink
Added setSkipEmptyValues() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Aug 29, 2019
1 parent 6bf6434 commit c9446f3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Facades/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Xml
/** @var \DOMElement */
protected $root;

protected $skip_empty_values = false;

public function __construct(string $root = 'root', array $attributes = [], bool $format_output = false)
{
$this->doc = new DOMDocument('1.0', 'utf-8');
Expand All @@ -38,6 +40,13 @@ public static function init(string $root = 'root', array $attributes = [], bool
return new self($root, $attributes, $format_output);
}

public function setSkipEmptyValues(): self
{
$this->skip_empty_values = true;

return $this;
}

public function doctype($qualified_name = null, $public_id = null, $system_id = null): self
{
$implementation = new DOMImplementation;
Expand Down Expand Up @@ -106,6 +115,10 @@ public function get(): string
private function setAttributes(DOMElement &$element, array $attributes = [])
{
foreach ($attributes as $name => $value) {
if ($this->skip_empty_values && empty($value)) {
continue;
}

$element->setAttribute($name, $value);
}
}
Expand Down

0 comments on commit c9446f3

Please sign in to comment.