1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\WSSecurity\XML\fed; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\WSSecurity\Assert\Assert; |
9
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
10
|
|
|
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; |
11
|
|
|
use SimpleSAML\XML\StringElementTrait; |
12
|
|
|
|
13
|
|
|
use function in_array; |
14
|
|
|
use function sprintf; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A AutomaticPseudonyms element |
18
|
|
|
* |
19
|
|
|
* @package simplesamlphp/ws-security |
20
|
|
|
*/ |
21
|
|
|
final class AutomaticPseudonyms extends AbstractFedElement implements SchemaValidatableElementInterface |
22
|
|
|
{ |
23
|
|
|
use SchemaValidatableElementTrait; |
|
|
|
|
24
|
|
|
use StringElementTrait; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @param bool $content |
29
|
|
|
*/ |
30
|
|
|
public function __construct(bool $content) |
31
|
|
|
{ |
32
|
|
|
$this->setContent($content ? 'true' : 'false'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Convert XML into a class instance |
38
|
|
|
* |
39
|
|
|
* @param \DOMElement $xml The XML element we should load |
40
|
|
|
* @return static |
41
|
|
|
* |
42
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
43
|
|
|
* If the qualified name of the supplied element is wrong |
44
|
|
|
*/ |
45
|
|
|
public static function fromXML(DOMElement $xml): static |
46
|
|
|
{ |
47
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
48
|
|
|
Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
49
|
|
|
|
50
|
|
|
Assert::oneOf( |
51
|
|
|
$xml->textContent, |
52
|
|
|
['0', '1', 'false', 'true'], |
53
|
|
|
sprintf( |
54
|
|
|
'The value \'%s\' of an %s:%s element must be a boolean.', |
55
|
|
|
$xml->textContent, |
56
|
|
|
static::NS_PREFIX, |
57
|
|
|
static::getLocalName(), |
58
|
|
|
), |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
return new static(in_array($xml->textContent, ['1', 'true'], true)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|