Commit 0e42de11 authored by Bas de Nooijer's avatar Bas de Nooijer

- some style fixes

- made readonly document really readonly
- updated test for readonly document
- fixed docblock in readwrite document
parent 2f2e4336
...@@ -129,10 +129,12 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter ...@@ -129,10 +129,12 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
return $data; return $data;
} }
function simplexmlToArray($xml) {
function simplexmlToArray($xml)
{
if (get_class($xml) == 'SimpleXMLElement') { if (get_class($xml) == 'SimpleXMLElement') {
$attributes = $xml->attributes(); $attributes = $xml->attributes();
foreach($attributes as $k=>$v) { foreach ($attributes as $k=>$v) {
if ($v) $a[$k] = (string) $v; if ($v) $a[$k] = (string) $v;
} }
$x = $xml; $x = $xml;
...@@ -140,7 +142,7 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter ...@@ -140,7 +142,7 @@ class Solarium_Client_Adapter_Stream extends Solarium_Client_Adapter
} }
if (is_array($xml)) { if (is_array($xml)) {
if (count($xml) == 0) return (string) $x; // for CDATA if (count($xml) == 0) return (string) $x; // for CDATA
foreach($xml as $key=>$value) { foreach ($xml as $key=>$value) {
$r[$key] = $this->simplexmlToArray($value); $r[$key] = $this->simplexmlToArray($value);
} }
if (isset($a)) $r['@attributes'] = $a; // Attributes if (isset($a)) $r['@attributes'] = $a; // Attributes
......
...@@ -64,6 +64,7 @@ class Solarium_Document_ReadOnly ...@@ -64,6 +64,7 @@ class Solarium_Document_ReadOnly
return $this->_fields; return $this->_fields;
} }
/** /**
* Magic access method for accessing fields as properties of this document * Magic access method for accessing fields as properties of this document
* object, by field name. * object, by field name.
...@@ -80,4 +81,18 @@ class Solarium_Document_ReadOnly ...@@ -80,4 +81,18 @@ class Solarium_Document_ReadOnly
return $this->_fields[$name]; return $this->_fields[$name];
} }
/**
* Magic method for setting a field as property of this object. Since this
* is a readonly document an exception will be thrown to prevent this.
*
* @param string $name
* @param string $value
* @return void
*/
public function __set($name, $value)
{
throw new Solarium_Exception('A readonly document cannot be altered');
}
} }
\ No newline at end of file
...@@ -172,7 +172,7 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly ...@@ -172,7 +172,7 @@ class Solarium_Document_ReadWrite extends Solarium_Document_ReadOnly
} }
/** /**
* Magic access method for accessing fields as properties of this document * Magic method for setting fields as properties of this document
* object, by field name. * object, by field name.
* *
* @param string $name * @param string $name
......
...@@ -66,4 +66,10 @@ class Solarium_Document_ReadOnlyTest extends PHPUnit_Framework_TestCase ...@@ -66,4 +66,10 @@ class Solarium_Document_ReadOnlyTest extends PHPUnit_Framework_TestCase
); );
} }
public function testSetField()
{
$this->setExpectedException('Solarium_Exception');
$this->_doc->newField = 'new value';
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment