Skip to content

Commit

Permalink
Arrayizable RequesterID
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jun 16, 2023
1 parent c1d0966 commit cae2604
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/SAML2/XML/samlp/RequesterID.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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()];
}
}

0 comments on commit cae2604

Please sign in to comment.