Passed
Push — master ( c2ab36...decaf7 )
by Tim
01:44
created

Extensions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML2\Assert\Assert;
9
use SimpleSAML\SAML2\Utils\XPath;
10
use SimpleSAML\SAML2\XML\ExtensionsTrait;
11
use SimpleSAML\XML\Chunk;
12
use SimpleSAML\XML\SchemaValidatableElementInterface;
13
use SimpleSAML\XML\SchemaValidatableElementTrait;
14
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
15
use SimpleSAML\XMLSchema\XML\Constants\NS;
16
17
/**
18
 * Class for handling SAML2 extensions.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class Extensions extends AbstractSamlpElement implements SchemaValidatableElementInterface
23
{
24
    use ExtensionsTrait;
25
    use SchemaValidatableElementTrait;
26
27
28
    /** The namespace-attribute for the xs:any element */
29
    public const string XS_ANY_ELT_NAMESPACE = NS::OTHER;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 29 at column 24
Loading history...
30
31
    /**
32
     * The exclusions for the xs:any element
33
     *
34
     * @var array<int, array<int, string>>
35
     */
36
    public const array XS_ANY_ELT_EXCLUSIONS = [
37
        ['urn:oasis:names:tc:SAML:2.0:assertion', '*'],
38
        ['urn:oasis:names:tc:SAML:2.0:metadata', '*'],
39
        ['urn:oasis:names:tc:SAML:2.0:protocol', '*'],
40
    ];
41
42
43
    /**
44
     * Create an Extensions object from its samlp:Extensions XML representation.
45
     *
46
     * For those supported extensions, an object of the corresponding class will be created. The rest will be added
47
     * as a \SimpleSAML\XML\Chunk object.
48
     *
49
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
50
     *   if the qualified name of the supplied element is wrong
51
     */
52
    public static function fromXML(DOMElement $xml): static
53
    {
54
        Assert::eq(
55
            $xml->namespaceURI,
56
            self::NS,
57
            'Unknown namespace \'' . strval($xml->namespaceURI) . '\' for Extensions element.',
58
            InvalidDOMElementException::class,
59
        );
60
        Assert::eq(
61
            $xml->localName,
62
            static::getClassName(static::class),
63
            'Invalid Extensions element \'' . $xml->localName . '\'',
64
            InvalidDOMElementException::class,
65
        );
66
        $ret = [];
67
68
        /** @var \DOMElement $node */
69
        foreach (XPath::xpQuery($xml, './*', XPath::getXPath($xml)) as $node) {
70
            $ret[] = new Chunk($node);
71
        }
72
73
        return new static($ret);
74
    }
75
}
76