Skip to content

Commit fed7417

Browse files
committed
Make SignedElement*::fromXML generic
1 parent 8fce905 commit fed7417

2 files changed

Lines changed: 11 additions & 27 deletions

File tree

src/XML/AbstractSignedXMLElement.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace SimpleSAML\XMLSecurity\XML;
66

77
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Exception\MissingElementException;
10+
use SimpleSAML\XML\Exception\TooManyElementsException;
811
use SimpleSAML\XMLSecurity\XML\ds\Signature;
912

1013
/**
@@ -39,7 +42,6 @@ abstract class AbstractSignedXMLElement implements SignedElementInterface
3942
*/
4043
protected function __construct(DOMElement $xml, Signature $signature)
4144
{
42-
// $this->element = $elt;
4345
$this->setStructure($xml);
4446
$this->setSignature($signature);
4547
}
@@ -96,5 +98,12 @@ public function toXML(DOMElement $parent = null): DOMElement
9698
* @param \DOMElement $xml
9799
* @return self
98100
*/
99-
abstract public static function fromXML(DOMElement $xml): object;
101+
public static function fromXML(DOMElement $xml): object
102+
{
103+
$signature = Signature::getChildrenOfClass($xml);
104+
Assert::minCount($signature, 1, MissingElementException::class);
105+
Assert::maxCount($signature, 1, TooManyElementsException::class);
106+
107+
return new self($xml, array_pop($signature));
108+
}
100109
}

tests/XML/CustomSigned.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,12 @@
44

55
namespace SimpleSAML\XMLSecurity\Test\XML;
66

7-
use DOMElement;
8-
use SimpleSAML\Assert\Assert;
9-
use SimpleSAML\XML\Chunk;
10-
use SimpleSAML\XML\Exception\MissingElementException;
11-
use SimpleSAML\XML\Exception\TooManyElementsException;
12-
use SimpleSAML\XML\Utils as XMLUtils;
13-
use SimpleSAML\XMLSecurity\XML\ds\Signature;
147
use SimpleSAML\XMLSecurity\XML\AbstractSignedXMLElement;
15-
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
168
use SimpleSAML\XMLSecurity\XML\SignedElementTrait;
179

1810
/**
1911
* @package simplesamlphp\saml2
2012
*/
2113
final class CustomSigned extends AbstractSignedXMLElement
2214
{
23-
use SignedElementTrait;
24-
25-
26-
/**
27-
* Create a class from XML
28-
*
29-
* @param \DOMElement $xml
30-
* @return self
31-
*/
32-
public static function fromXML(DOMElement $xml): object
33-
{
34-
$signature = Signature::getChildrenOfClass($xml);
35-
Assert::minCount($signature, 1, MissingElementException::class);
36-
Assert::maxCount($signature, 1, TooManyElementsException::class);
37-
38-
return new self($xml, array_pop($signature));
39-
}
4015
}

0 commit comments

Comments
 (0)