-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
online-from and online-to cannot be empty (#82)
* online-from/to * Remove unnecessary test and amend other fixtures * Add nilEmptyWriter and amend product tests/fixtures * Add test and remove an unnecessary method * Categories test and tidy up * Update CategoriesTest.php * Amend and fix tests * Swap params over - maybe I had gone mad yesterday * Add more tests * Amend test Co-authored-by: maxakropolis <andy@andystafford.co.uk>
- Loading branch information
1 parent
1f6efc4
commit 55099d7
Showing
8 changed files
with
133 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace DemandwareXml\Writer\Xml; | ||
|
||
class NilEmptyWriter | ||
{ | ||
private $writer; | ||
|
||
public function __construct(XmlWriter $writer) | ||
{ | ||
$this->writer = $writer; | ||
} | ||
|
||
public function writeElement($name, $content = null): bool | ||
{ | ||
if (XmlFormatter::isEmptyValue($content)) { | ||
return $this->writeElementWithAttributes($name); | ||
} | ||
|
||
return $this->writer->writeElement($name, $content); | ||
} | ||
|
||
public function writeAttribute($name, $value): bool | ||
{ | ||
return $this->writer->writeAttribute($name, $value); | ||
} | ||
|
||
public function writeElementWithAttributes($name, $content = null, array $attributes = []): bool | ||
{ | ||
$this->writer->startElement($name); | ||
|
||
foreach ($attributes as $attrName => $attrContent) { | ||
$this->writeAttribute($attrName, $attrContent); | ||
} | ||
|
||
if (XmlFormatter::isEmptyValue($content)) { | ||
$this->writeAttribute('xsi:nil', 'true'); | ||
$this->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); | ||
} else { | ||
$this->writer->text($content); | ||
} | ||
|
||
$this->writer->endElement(); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters