Skip to content

Commit

Permalink
Merge pull request #31 from Hywan/cs
Browse files Browse the repository at this point in the history
Fix CS
  • Loading branch information
evert committed Jan 21, 2015
2 parents a5699a8 + 0bf4125 commit 77336b6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ function write($value) {

reset($value);
foreach ($value as $name => $item) {

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');
Expand All @@ -118,10 +120,13 @@ function write($value) {
$attributes = isset($item['attributes']) ? $item['attributes'] : [];
$name = $item['name'];
$item = $item['value'];

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

// This item has a text index. We expect to be an array with a value and optional attributes.
$attributes = isset($item['attributes']) ? $item['attributes'] : [];
$item = $item['value'];

} else {
// If it's an array with text-indices, we expect every item's
// key to be an xml element name in clark notation.
Expand All @@ -133,6 +138,7 @@ function write($value) {
$this->writeAttributes($attributes);
$this->write($item);
$this->endElement();

}

} elseif (is_object($value)) {
Expand All @@ -152,6 +158,7 @@ function write($value) {
function startElement($name) {

if ($name[0]==='{') {

list($namespace, $localName) =
Util::parseClarkNotation($name);

Expand All @@ -164,9 +171,11 @@ function startElement($name) {
}
$result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
}

} else {
$result = parent::startElement($name);
}

if (!$this->namespacesWritten) {

foreach($this->namespaceMap as $namespace => $prefix) {
Expand Down Expand Up @@ -198,6 +207,7 @@ function writeElement($name, $content = null) {
$this->endElement();

}

/**
* Writes a list of attributes.
*
Expand Down Expand Up @@ -232,13 +242,13 @@ function writeAttributes(array $attributes) {
function writeAttribute($name, $value) {

if ($name[0] === '{') {

list(
$namespace,
$localName
) = Util::parseClarkNotation($name);

if (array_key_exists($namespace,$this->namespaceMap)) {

// It's an attribute with a namespace we know
$this->writeAttribute(
$this->namespaceMap[$namespace] . ':' . $localName,
Expand All @@ -258,6 +268,7 @@ function writeAttribute($name, $value) {
);

}

} else {
return parent::writeAttribute($name, $value);
}
Expand Down

0 comments on commit 77336b6

Please sign in to comment.