Skip to content

Commit

Permalink
load properties in XML loader class, too
Browse files Browse the repository at this point in the history
  • Loading branch information
cweiske committed Apr 2, 2013
1 parent 35f578c commit 950c4e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 44 deletions.
28 changes: 7 additions & 21 deletions src/XML/XRD/Element/Property.php
Expand Up @@ -40,30 +40,16 @@ class XML_XRD_Element_Property
public $type; public $type;


/** /**
* Create a new instance and load data from the XML element * Create a new instance
* *
* @param SimpleXMLElement|string $typeOrXml SimpleXMLElement representing * @param string $type String representing the property type
* the <Property>, or a string * @param string $value Value of the property, may be NULL
* representing the property type
* @param string $value Value of the property, may be
* NULL. Ignored when $x is a
* SimpleXMLElement
*/ */
public function __construct($typeOrXml = null, $value = null) public function __construct($type = null, $value = null)
{ {
if ($typeOrXml instanceof SimpleXMLElement) { $this->type = $type;
if (isset($typeOrXml['type'])) { $this->value = $value;
$this->type = (string)$typeOrXml['type'];
}
$s = (string)$typeOrXml;
if ($s != '') {
$this->value = $s;
}
} else {
$this->type = $typeOrXml;
$this->value = $value;
}
} }
} }


?> ?>
23 changes: 22 additions & 1 deletion src/XML/XRD/Loader/XML.php
Expand Up @@ -100,7 +100,7 @@ protected function loadProperties(
XML_XRD_PropertyAccess $store, SimpleXMLElement $x XML_XRD_PropertyAccess $store, SimpleXMLElement $x
) { ) {
foreach ($x->Property as $xProp) { foreach ($x->Property as $xProp) {
$store->properties[] = new XML_XRD_Element_Property($xProp); $store->properties[] = $this->loadProperty($xProp);
} }
} }


Expand Down Expand Up @@ -134,5 +134,26 @@ protected function loadLink(SimpleXMLElement $x)


return $link; 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;
}
} }
?> ?>
22 changes: 0 additions & 22 deletions tests/XML/XRD/Element/PropertyTest.php
Expand Up @@ -3,28 +3,6 @@


class XML_XRD_Element_PropertyTest extends PHPUnit_Framework_TestCase 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() public function test__constructParams()
{ {
$prop = new XML_XRD_Element_Property( $prop = new XML_XRD_Element_Property(
Expand Down

0 comments on commit 950c4e3

Please sign in to comment.