From cae26046f2e19a339a18e072c670f2194dd3b03a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Fri, 16 Jun 2023 19:56:55 +0200 Subject: [PATCH] Arrayizable RequesterID --- src/SAML2/XML/samlp/RequesterID.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/SAML2/XML/samlp/RequesterID.php b/src/SAML2/XML/samlp/RequesterID.php index 48850c65c..e92f479f9 100644 --- a/src/SAML2/XML/samlp/RequesterID.php +++ b/src/SAML2/XML/samlp/RequesterID.php @@ -6,10 +6,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; +use SimpleSAML\SAML2\Exception\ArrayValidationException; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\StringElementTrait; +use function array_key_first; + /** * Class representing a samlp:RequesterID element. * @@ -58,4 +61,30 @@ public static function fromXML(DOMElement $xml): static return new static($xml->textContent); } + + + /** + * Create a class from an array + * + * @param array $data + * @return static + */ + public static function fromArray(array $data): static + { + Assert::allString($data, ArrayValidationException::class); + + $index = array_key_first($data); + return new static($data[$index]); + } + + + /** + * Create an array from this class + * + * @return array + */ + public function toArray(): array + { + return [$this->getContent()]; + } }