Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to xsd-types #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"simplesamlphp/assert": "~1.8.0",
"simplesamlphp/composer-xmlprovider-installer": "~1.0.1",
"simplesamlphp/xml-common": "~1.24.0"
"simplesamlphp/xml-common": "dev-feature/xsd-types"
},
"require-dev": {
"simplesamlphp/simplesamlphp-test-framework": "^1.8"
Expand Down
6 changes: 2 additions & 4 deletions src/XML/env_200106/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use SimpleSAML\Assert\Assert;
use SimpleSAML\SOAP\Exception\ProtocolViolationException;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

use function array_diff;
Expand Down
3 changes: 1 addition & 2 deletions src/XML/env_200106/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
10 changes: 3 additions & 7 deletions src/XML/env_200106/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
7 changes: 2 additions & 5 deletions src/XML/env_200106/Fault.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};

/**
* Class representing a env:Fault element.
Expand Down
32 changes: 5 additions & 27 deletions src/XML/env_200106/FaultActor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace SimpleSAML\SOAP\XML\env_200106;

use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\StringElementTrait;
use SimpleSAML\XML\Type\AnyURIValue;
use SimpleSAML\XML\TypedTextContentTrait;

/**
* Class representing a faultactor element.
Expand All @@ -16,7 +15,7 @@
*/
final class FaultActor extends AbstractElement
{
use StringElementTrait;
use TypedTextContentTrait;

/** @var string */
public const LOCALNAME = 'faultactor';
Expand All @@ -27,27 +26,6 @@ final class FaultActor extends AbstractElement
/** @var null */
public const NS_PREFIX = null;


/**
* Initialize an faultactor
*
* @param string $faultActor
*/
public function __construct(string $faultActor)
{
$this->setContent($faultActor);
}


/**
* Validate the content of the element.
*
* @param string $content The value to go in the XML textContent
* @throws \Exception on failure
* @return void
*/
protected function validateContent(string $content): void
{
Assert::validURI($content, SchemaViolationException::class); // Covers the empty string
}
/** @var string */
public const TEXTCONTENT_TYPE = AnyURIValue::class;
}
19 changes: 5 additions & 14 deletions src/XML/env_200106/FaultCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace SimpleSAML\SOAP\XML\env_200106;

use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\QNameElementTrait;
use SimpleSAML\XML\Type\QNameValue;
use SimpleSAML\XML\TypedTextContentTrait;

/**
* Class representing a faultcode element.
Expand All @@ -14,7 +15,7 @@
*/
final class FaultCode extends AbstractElement
{
use QNameElementTrait;
use TypedTextContentTrait;

/** @var string */
public const LOCALNAME = 'faultcode';
Expand All @@ -25,16 +26,6 @@ final class FaultCode extends AbstractElement
/** @var null */
public const NS_PREFIX = null;


/**
* Initialize an faultcode
*
* @param string $qname
* @param string|null $namespaceUri
*/
public function __construct(string $qname, ?string $namespaceUri = null)
{
$this->setContent($qname);
$this->setContentNamespaceUri($namespaceUri);
}
/** @var string */
public const TEXTCONTENT_TYPE = QNameValue::class;
}
17 changes: 5 additions & 12 deletions src/XML/env_200106/FaultString.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace SimpleSAML\SOAP\XML\env_200106;

use SimpleSAML\XML\AbstractElement;
use SimpleSAML\XML\StringElementTrait;
use SimpleSAML\XML\Type\StringValue;
use SimpleSAML\XML\TypedTextContentTrait;

/**
* Class representing a faultstring element.
Expand All @@ -14,7 +15,7 @@
*/
final class FaultString extends AbstractElement
{
use StringElementTrait;
use TypedTextContentTrait;

/** @var string */
public const LOCALNAME = 'faultstring';
Expand All @@ -25,14 +26,6 @@ final class FaultString extends AbstractElement
/** @var null */
public const NS_PREFIX = null;


/**
* Initialize an faultstring
*
* @param string $faultString
*/
public function __construct(string $faultString)
{
$this->setContent($faultString);
}
/** @var string */
public const TEXTCONTENT_TYPE = StringValue::class;
}
6 changes: 2 additions & 4 deletions src/XML/env_200106/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
6 changes: 2 additions & 4 deletions src/XML/env_200305/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use SimpleSAML\Assert\Assert;
use SimpleSAML\SOAP\Exception\ProtocolViolationException;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

use function array_pop;
Expand Down
25 changes: 1 addition & 24 deletions src/XML/env_200305/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SOAP\Constants as C;
use SimpleSAML\SOAP\Exception\ProtocolViolationException;
use SimpleSAML\SOAP\XML\env_200305\FaultEnum;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};

/**
* Class representing a env:Code element.
Expand All @@ -30,19 +25,6 @@ public function __construct(
protected Value $value,
protected ?Subcode $subcode = null,
) {
@list($prefix, $localName) = preg_split('/:/', $value->getContent(), 2);
/** @var string|null $localName */
if ($localName === null) {
// We don't have a prefixed value here
$localName = $prefix;
}

Assert::oneOf(
FaultEnum::from($localName),
FaultEnum::cases(),
'Invalid top-level Value',
ProtocolViolationException::class,
);
}


Expand Down Expand Up @@ -81,11 +63,6 @@ public static function fromXML(DOMElement $xml): static
$value = Value::getChildrenOfClass($xml);
Assert::count($value, 1, 'Must contain exactly one Value', MissingElementException::class);

// Assert that the namespace of the value matches the SOAP-ENV namespace
@list($prefix, $localName) = preg_split('/:/', $value[0]->getContent(), 2);
$namespace = $xml->lookupNamespaceUri($prefix);
Assert::same($namespace, C::NS_SOAP_ENV_12);

$subcode = Subcode::getChildrenOfClass($xml);
Assert::maxCount($subcode, 1, 'Cannot process more than one Subcode element.', TooManyElementsException::class);

Expand Down
3 changes: 1 addition & 2 deletions src/XML/env_200305/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
7 changes: 2 additions & 5 deletions src/XML/env_200305/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
7 changes: 2 additions & 5 deletions src/XML/env_200305/Fault.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\Exception\MissingElementException;
use SimpleSAML\XML\Exception\TooManyElementsException;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};

/**
* Class representing a env:Fault element.
Expand Down
6 changes: 2 additions & 4 deletions src/XML/env_200305/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\InvalidDOMElementException;
use SimpleSAML\XML\ExtendableAttributesTrait;
use SimpleSAML\XML\ExtendableElementTrait;
use SimpleSAML\XML\SchemaValidatableElementInterface;
use SimpleSAML\XML\SchemaValidatableElementTrait;
use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait};
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
use SimpleSAML\XML\XsNamespace as NS;

/**
Expand Down
32 changes: 5 additions & 27 deletions src/XML/env_200305/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace SimpleSAML\SOAP\XML\env_200305;

use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\SchemaViolationException;
use SimpleSAML\XML\StringElementTrait;
use SimpleSAML\XML\Type\AnyURIValue;
use SimpleSAML\XML\TypedTextContentTrait;

/**
* Class representing a env:Node element.
Expand All @@ -15,29 +14,8 @@
*/
final class Node extends AbstractSoapElement
{
use StringElementTrait;
use TypedTextContentTrait;


/**
* Initialize a env:Node
*
* @param string $node
*/
public function __construct(string $node)
{
$this->setContent($node);
}


/**
* Validate the content of the element.
*
* @param string $content The value to go in the XML textContent
* @throws \Exception on failure
* @return void
*/
protected function validateContent(string $content): void
{
Assert::validURI($content, SchemaViolationException::class); // Covers the empty string
}
/** @var string */
public const TEXTCONTENT_TYPE = AnyURIValue::class;
}
Loading