Permalink
Browse files

load properties in XML loader class, too

  • Loading branch information...
1 parent 35f578c commit 950c4e36d76db44ced8d17e50f7c3b63d73ab400 @cweiske cweiske committed Apr 2, 2013
Showing with 29 additions and 44 deletions.
  1. +7 −21 src/XML/XRD/Element/Property.php
  2. +22 −1 src/XML/XRD/Loader/XML.php
  3. +0 −22 tests/XML/XRD/Element/PropertyTest.php
@@ -40,30 +40,16 @@ class XML_XRD_Element_Property
public $type;
/**
- * Create a new instance and load data from the XML element
+ * Create a new instance
*
- * @param SimpleXMLElement|string $typeOrXml SimpleXMLElement representing
- * the <Property>, or a string
- * representing the property type
- * @param string $value Value of the property, may be
- * NULL. Ignored when $x is a
- * SimpleXMLElement
+ * @param string $type String representing the property type
+ * @param string $value Value of the property, may be NULL
*/
- public function __construct($typeOrXml = null, $value = null)
+ public function __construct($type = null, $value = null)
{
- if ($typeOrXml instanceof SimpleXMLElement) {
- if (isset($typeOrXml['type'])) {
- $this->type = (string)$typeOrXml['type'];
- }
- $s = (string)$typeOrXml;
- if ($s != '') {
- $this->value = $s;
- }
- } else {
- $this->type = $typeOrXml;
- $this->value = $value;
- }
+ $this->type = $type;
+ $this->value = $value;
}
}
-?>
+?>
@@ -100,7 +100,7 @@ protected function loadProperties(
XML_XRD_PropertyAccess $store, SimpleXMLElement $x
) {
foreach ($x->Property as $xProp) {
- $store->properties[] = new XML_XRD_Element_Property($xProp);
+ $store->properties[] = $this->loadProperty($xProp);
}
}
@@ -134,5 +134,26 @@ protected function loadLink(SimpleXMLElement $x)
return $link;
}
+
+ /**
+ * Create a property element object from XML element
+ *
+ * @param object $x XML property element
+ *
+ * @return XML_XRD_Element_Property Created link object
+ */
+ protected function loadProperty(SimpleXMLElement $x)
+ {
+ $prop = new XML_XRD_Element_Property();
+ if (isset($x['type'])) {
+ $prop->type = (string)$x['type'];
+ }
+ $s = (string)$x;
+ if ($s != '') {
+ $prop->value = $s;
+ }
+
+ return $prop;
+ }
}
?>
@@ -3,28 +3,6 @@
class XML_XRD_Element_PropertyTest extends PHPUnit_Framework_TestCase
{
- public function test__constructXmlNull()
- {
- $prop = new XML_XRD_Element_Property(
- new SimpleXMLElement(
- '<Property type="http://spec.example.net/type/person" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />'
- )
- );
- $this->assertEquals('http://spec.example.net/type/person', $prop->type);
- $this->assertNull($prop->value);
- }
-
- public function test__constructXmlValue()
- {
- $prop = new XML_XRD_Element_Property(
- new SimpleXMLElement(
- '<Property type="http://spec.example.net/created/1.0">1970-01-01</Property>'
- )
- );
- $this->assertEquals('http://spec.example.net/created/1.0', $prop->type);
- $this->assertEquals('1970-01-01', $prop->value);
- }
-
public function test__constructParams()
{
$prop = new XML_XRD_Element_Property(

0 comments on commit 950c4e3

Please sign in to comment.