diff --git a/CHANGELOG.md b/CHANGELOG.md index 22dbf4b..ce55e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/Writer.php b/lib/Writer.php index 4edba33..bea3853 100644 --- a/lib/Writer.php +++ b/lib/Writer.php @@ -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)) { diff --git a/tests/Sabre/Xml/WriterTest.php b/tests/Sabre/Xml/WriterTest.php index c48da51..453f419 100644 --- a/tests/Sabre/Xml/WriterTest.php +++ b/tests/Sabre/Xml/WriterTest.php @@ -72,7 +72,6 @@ function testSimpleAttributes() { ); } - function testMixedSyntax() { $this->compare([ '{http://sabredav.org/ns}root' => [ @@ -148,6 +147,31 @@ function testArrayFormat2() { text +HI + ); + + } + + /** + * @depends testArrayFormat2 + */ + function testArrayFormat2NoValue() { + + $this->compare([ + '{http://sabredav.org/ns}root' => [ + [ + 'name' => '{http://sabredav.org/ns}elem1', + 'attributes' => [ + 'attr1' => 'attribute value', + ], + ], + ], + ], << + + + + HI );