-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use SimpleSAML\WSSecurity\Constants as C; | ||
use SimpleSAML\XML\AbstractElement; | ||
|
||
/** | ||
* Abstract class to be implemented by all the classes in this namespace | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
abstract class AbstractWsxElement extends AbstractElement | ||
{ | ||
/** @var string */ | ||
public const NS = C::NS_METADATA_EXCHANGE; | ||
|
||
/** @var string */ | ||
public const NS_PREFIX = 'wsx'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use SimpleSAML\XML\URIElementTrait; | ||
|
||
/** | ||
* An Dialect element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class Dialect extends AbstractWsxElement | ||
{ | ||
use URIElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\TooManyElementsException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
use function array_pop; | ||
|
||
/** | ||
* Class defining the GetMetadata element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class GetMetadata extends AbstractWsxElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* GetMetadata constructor | ||
* | ||
* @param \SimpleSAML\WSSecurity\XML\wsx\Dialect|null $dialect | ||
* @param \SimpleSAML\WSSecurity\XML\wsx\Identifier|null $identifier | ||
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
*/ | ||
final public function __construct( | ||
protected ?Dialect $dialect = null, | ||
protected ?Identifier $identifier = null, | ||
array $namespacedAttributes = [] | ||
) { | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Get the dialect property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsx\Dialect|null | ||
*/ | ||
public function getDialect(): ?Dialect | ||
{ | ||
return $this->dialect; | ||
} | ||
|
||
|
||
/** | ||
* Get the identifier property. | ||
* | ||
* @return \SimpleSAML\WSSecurity\XML\wsx\Identifier|null | ||
*/ | ||
public function getIdentifier(): ?Identifier | ||
{ | ||
return $this->identifier; | ||
} | ||
|
||
|
||
/** | ||
* Test if an object, at the state it's in, would produce an empty XML-element | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmptyElement(): bool | ||
{ | ||
return empty($this->getDialect()) | ||
&& empty($this->getIdentifier()) | ||
&& empty($this->getAttributesNS()); | ||
} | ||
|
||
|
||
/** | ||
* Create an instance of this object from its XML representation. | ||
* | ||
* @param \DOMElement $xml | ||
* @return static | ||
* | ||
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException | ||
* if the qualified name of the supplied element is wrong | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
$dialect = Dialect::getChildrenOfClass($xml); | ||
Assert::maxCount($dialect, 1, TooManyElementsException::class); | ||
|
||
$identifier = Identifier::getChildrenOfClass($xml); | ||
Assert::maxCount($identifier, 1, TooManyElementsException::class); | ||
|
||
return new static( | ||
array_pop($dialect), | ||
array_pop($identifier), | ||
self::getAttributesNSFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Add this GetMetadata to an XML element. | ||
* | ||
* @param \DOMElement $parent The element we should append this GetMetadata to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::instantiateParentElement($parent); | ||
|
||
$this->getDialect()?->toXML($e); | ||
$this->getIdentifier()?->toXML($e); | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use SimpleSAML\XML\URIElementTrait; | ||
|
||
/** | ||
* An Identifier element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class Identifier extends AbstractWsxElement | ||
{ | ||
use URIElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use SimpleSAML\XML\URIElementTrait; | ||
|
||
/** | ||
* An Location element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class Location extends AbstractWsxElement | ||
{ | ||
use URIElementTrait; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\WSSecurity\XML\wsx; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Chunk; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\ExtendableAttributesTrait; | ||
use SimpleSAML\XML\ExtendableElementTrait; | ||
use SimpleSAML\XML\XsNamespace as NS; | ||
|
||
/** | ||
* Class defining the Metadata element | ||
* | ||
* @package tvdijen/ws-security | ||
*/ | ||
final class Metadata extends AbstractWsxElement | ||
{ | ||
use ExtendableAttributesTrait; | ||
use ExtendableElementTrait; | ||
|
||
/** The namespace-attribute for the xs:any element */ | ||
public const XS_ANY_ELT_NAMESPACE = NS::OTHER; | ||
|
||
/** The namespace-attribute for the xs:anyAttribute element */ | ||
public const XS_ANY_ATTR_NAMESPACE = NS::OTHER; | ||
|
||
|
||
/** | ||
* Metadata constructor | ||
* | ||
* @param array<\SimpleSAML\WSSecurity\XML\wsx\MetadataSection> $metadataSection | ||
* @param array<\SimpleSAML\XML\SerializableElementInterface> $children | ||
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes | ||
*/ | ||
final public function __construct( | ||
protected array $metadataSection = [], | ||
array $children = [], | ||
array $namespacedAttributes = [] | ||
) { | ||
$this->setElements($children); | ||
$this->setAttributesNS($namespacedAttributes); | ||
} | ||
|
||
|
||
/** | ||
* Get the child property. | ||
* | ||
* @return array<\SimpleSAML\WSSecurity\XML\wsx\MetadataSection> | ||
*/ | ||
public function getMetadataSection(): array | ||
{ | ||
return $this->metadataSection; | ||
} | ||
|
||
|
||
/** | ||
* Test if an object, at the state it's in, would produce an empty XML-element | ||
* | ||
* @return bool | ||
*/ | ||
public function isEmptyElement(): bool | ||
{ | ||
return empty($this->getMetadataSection()) | ||
&& empty($this->getElements()) | ||
&& empty($this->getAttributesNS()); | ||
} | ||
|
||
|
||
/** | ||
* Create an instance of this object from its XML representation. | ||
* | ||
* @param \DOMElement $xml | ||
* @return static | ||
* | ||
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException | ||
* if the qualified name of the supplied element is wrong | ||
*/ | ||
public static function fromXML(DOMElement $xml): static | ||
{ | ||
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); | ||
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); | ||
|
||
$children = []; | ||
foreach ($xml->childNodes as $child) { | ||
if (!($child instanceof DOMElement)) { | ||
continue; | ||
} elseif ($child->namespaceURI === static::NS) { | ||
continue; | ||
} | ||
|
||
$children[] = new Chunk($child); | ||
} | ||
|
||
return new static( | ||
MetadataSection::getChildrenOfClass($xml), | ||
$children, | ||
self::getAttributesNSFromXML($xml), | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Add this Metadata to an XML element. | ||
* | ||
* @param \DOMElement $parent The element we should append this Metadata to. | ||
* @return \DOMElement | ||
*/ | ||
public function toXML(DOMElement $parent = null): DOMElement | ||
{ | ||
$e = parent::instantiateParentElement($parent); | ||
|
||
foreach ($this->getMetadataSection() as $metadataSection) { | ||
$metadataSection->toXML($e); | ||
} | ||
|
||
foreach ($this->getElements() as $elt) { | ||
if (!$elt->isEmptyElement()) { | ||
$elt->toXML($e); | ||
} | ||
} | ||
|
||
foreach ($this->getAttributesNS() as $attr) { | ||
$attr->toXML($e); | ||
} | ||
|
||
return $e; | ||
} | ||
} |
Oops, something went wrong.