/** * This function sets the value for the specified key. * * @access public * @override * @param string $key the name of the property * @param mixed $value the value of the property * @throws Throwable_InvalidProperty_Exception indicates that the specified property is * either inaccessible or undefined */ public function __set($key, $value) { switch ($key) { case 'value': if (is_object($value) and $value instanceof SimpleXMLElement) { $value = $value->asXML(); } else { if (is_array($value)) { $value = XML::encode($value, TRUE); } } $this->model->{$this->metadata['field']} = $value; break; default: throw new Throwable_InvalidProperty_Exception('Message: Unable to set the specified property. Reason: Property :key is either inaccessible or undefined.', array(':key' => $key, ':value' => $value)); break; } }
public function testDecodeEncode() { $expected = "<?xml version=\"1.0\"?>\n" . "<User>\n" . " <Name>Joby Walker</Name>\n" . " <HasSkills>false</HasSkills>\n" . " <Locations>\n" . " <Location>\n" . " <Type>work</Type>\n" . " <City>Seattle</City>\n" . " </Location>\n" . " <Location>\n" . " <Type>home</Type>\n" . " <City>Seattle</City>\n" . " <Cats>2</Cats>\n" . " <Dogs/>\n" . " </Location>\n" . " </Locations>\n" . "</User>"; $this->assertEquals($expected, XML::encode(XML::decode($expected), null, array('declare' => true, 'offset' => ' ', 'depth' => -1))); $this->assertEquals($expected, XML::encode(XML::decode($expected, array('StripContainer' => true)), 'User', array('declare' => true, 'offset' => ' '))); }