Skip to content
This repository was archived by the owner on Jun 28, 2025. It is now read-only.

Commit d9e4896

Browse files
committed
Add xs:all element
1 parent c2d32f4 commit d9e4896

File tree

3 files changed

+134
-2
lines changed

3 files changed

+134
-2
lines changed

src/XML/xsd/AbstractAll.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XSD\XML\xsd;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\XML\Exception\SchemaViolationException;
9+
use SimpleSAML\XML\Type\IDValue;
10+
use SimpleSAML\XSD\Type\{MinOccursValue, MaxOccursValue};
11+
//use SimpleSAML\XSD\XML\xsd\NamespaceEnum;
12+
use SimpleSAML\XML\XsNamespace;
13+
14+
/**
15+
* Abstract class representing the explicitGroup-type.
16+
*
17+
* @package simplesamlphp/xml-xsd
18+
*/
19+
abstract class AbstractAll extends AbstractExplicitGroup
20+
{
21+
/** The namespace-attribute for the xs:anyAttribute element */
22+
public const XS_ANY_ATTR_NAMESPACE = XsNamespace::OTHER;
23+
// public const XS_ANY_ATTR_NAMESPACE = NamespaceEnum::Other;
24+
25+
26+
/**
27+
* All constructor
28+
*
29+
* @param \SimpleSAML\XSD\Type\MinOccursValue|null $minOccurs
30+
* @param \SimpleSAML\XSD\Type\MaxOccursValue|null $maxOccurs
31+
* @param array<\SimpleSAML\XSD\XML\xsd\NestedParticleInterface> $particles
32+
* @param \SimpleSAML\XSD\XML\xsd\Annotation|null $annotation
33+
* @param \SimpleSAML\XML\Type\IDValue|null $id
34+
* @param array<\SimpleSAML\XML\Attribute> $namespacedAttributes
35+
*/
36+
public function __construct(
37+
?MinOccursValue $minOccurs = null,
38+
?MaxOccursValue $maxOccurs = null,
39+
array $particles = [],
40+
?Annotation $annotation = null,
41+
?IDValue $id = null,
42+
array $namespacedAttributes = [],
43+
) {
44+
Assert::oneOf($minOccurs->toInteger(), [0, 1], SchemaViolationException::class);
45+
Assert::same($maxOccurs->toInteger(), 1, SchemaViolationException::class);
46+
47+
parent::__construct(
48+
nestedParticles: $particles,
49+
minOccurs: $minOccurs,
50+
maxOccurs: $maxOccurs,
51+
annotation: $annotation,
52+
id: $id,
53+
namespacedAttributes: $namespacedAttributes,
54+
);
55+
}
56+
}

src/XML/xsd/AbstractNamedGroup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public function __construct(
4545
);
4646

4747
if ($particle instanceof All) {
48-
Assert::null($particle->getMinCount(), SchemaViolationException::class);
49-
Assert::null($particle->getMaxCount(), SchemaViolationException::class);
48+
Assert::null($particle->getMinOccurs(), SchemaViolationException::class);
49+
Assert::null($particle->getMaxOccurs(), SchemaViolationException::class);
5050
}
5151

5252
parent::__construct(

src/XML/xsd/All.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XSD\XML\xsd;
6+
7+
use DOMElement;
8+
use SimpleSAML\Assert\Assert;
9+
use SimpleSAML\XML\Exception\{
10+
InvalidDOMElementException,
11+
MissingElementException,
12+
SchemaViolationException,
13+
TooManyElementsException,
14+
};
15+
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
16+
use SimpleSAML\XML\Type\{IDValue, NCNameValue, QNameValue};
17+
use SimpleSAML\XSD\Type\{MinOccursValue, MaxOccursValue};
18+
19+
use function array_merge;
20+
use function array_pop;
21+
22+
/**
23+
* Class representing the all-element.
24+
*
25+
* @package simplesamlphp/xml-xsd
26+
*/
27+
final class All extends AbstractAll implements ParticleInterface, SchemaValidatableElementInterface
28+
{
29+
use SchemaValidatableElementTrait;
30+
31+
/** @var string */
32+
public const LOCALNAME = 'all';
33+
34+
35+
/**
36+
* Create an instance of this object from its XML representation.
37+
*
38+
* @param \DOMElement $xml
39+
* @return static
40+
*
41+
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
42+
* if the qualified name of the supplied element is wrong
43+
*/
44+
public static function fromXML(DOMElement $xml): static
45+
{
46+
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
47+
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class);
48+
49+
// Prohibited attributes
50+
$name = self::getOptionalAttribute($xml, 'name', NCNameValue::class, null);
51+
Assert::null($name, SchemaViolationException::class);
52+
53+
$ref = self::getOptionalAttribute($xml, 'ref', QNameValue::class, null);
54+
Assert::null($ref, SchemaViolationException::class);
55+
56+
$annotation = Annotation::getChildrenOfClass($xml);
57+
Assert::maxCount($annotation, 1, TooManyElementsException::class);
58+
59+
$all = All::getChildrenOfClass($xml);
60+
$choice = Choice::getChildrenOfClass($xml);
61+
$sequence = Sequence::getChildrenOfClass($xml);
62+
63+
$particles = array_merge($all, $choice, $sequence);
64+
Assert::minCount($particles, 1, MissingElementException::class);
65+
Assert::maxCount($particles, 1, TooManyElementsException::class);
66+
67+
return new static(
68+
self::getOptionalAttribute($xml, 'minCount', MinOccursValue::class, null),
69+
self::getOptionalAttribute($xml, 'maxCount', MaxOccursValue::class, null),
70+
$particles,
71+
annotation: array_pop($annotation),
72+
id: self::getOptionalAttribute($xml, 'id', IDValue::class, null),
73+
namespacedAttributes: self::getAttributesNSFromXML($xml),
74+
);
75+
}
76+
}

0 commit comments

Comments
 (0)