Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ ChangeLog
`Sabre\Xml\Service::expect()`.
* Moved some parsing logic to `Reader::getDeserializerForElementName()`,
so people with more advanced use-cases can implement their own logic there.
* When serializing elements using arrays, the `value` key in the array is now
optional.


1.2.0 (2015-08-30)
Expand Down
6 changes: 3 additions & 3 deletions lib/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ function write($value) {
if (is_int($name)) {

// This item has a numeric index. We expect to be an array with a name and a value.
if (!is_array($item) || !array_key_exists('name', $item) || !array_key_exists('value', $item)) {
throw new InvalidArgumentException('When passing an array to ->write with numeric indices, every item must be an array containing the "name" and "value" key');
if (!is_array($item) || !array_key_exists('name', $item)) {
throw new InvalidArgumentException('When passing an array to ->write with numeric indices, every item must be an array containing at least the "name" key');
}

$attributes = isset($item['attributes']) ? $item['attributes'] : [];
$name = $item['name'];
$item = $item['value'];
$item = isset($item['value']) ? $item['value'] : [];

} elseif (is_array($item) && array_key_exists('value', $item)) {

Expand Down
26 changes: 25 additions & 1 deletion tests/Sabre/Xml/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function testSimpleAttributes() {
);

}

function testMixedSyntax() {
$this->compare([
'{http://sabredav.org/ns}root' => [
Expand Down Expand Up @@ -148,6 +147,31 @@ function testArrayFormat2() {
<s:elem1 attr1="attribute value">text</s:elem1>
</s:root>

HI
);

}

/**
* @depends testArrayFormat2
*/
function testArrayFormat2NoValue() {

$this->compare([
'{http://sabredav.org/ns}root' => [
[
'name' => '{http://sabredav.org/ns}elem1',
'attributes' => [
'attr1' => 'attribute value',
],
],
],
], <<<HI
<?xml version="1.0"?>
<s:root xmlns:s="http://sabredav.org/ns">
<s:elem1 attr1="attribute value"/>
</s:root>

HI
);

Expand Down