1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\CAS\XML\cas; |
6
|
|
|
|
7
|
|
|
use DOMElement; |
8
|
|
|
use SimpleSAML\Assert\Assert; |
9
|
|
|
use SimpleSAML\CAS\Constants as C; |
10
|
|
|
use SimpleSAML\XML\Exception\InvalidDOMElementException; |
11
|
|
|
use SimpleSAML\XML\Exception\MissingElementException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class for CAS proxies |
15
|
|
|
* |
16
|
|
|
* @package simplesamlphp/cas |
17
|
|
|
*/ |
18
|
|
|
final class Proxies extends AbstractCasElement |
19
|
|
|
{ |
20
|
|
|
/** @var string */ |
21
|
|
|
final public const LOCALNAME = 'proxies'; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Initialize a Proxies element. |
26
|
|
|
* |
27
|
|
|
* @param \SimpleSAML\CAS\XML\cas\Proxy[] $proxy |
28
|
|
|
*/ |
29
|
|
|
final public function __construct( |
30
|
|
|
protected array $proxy = [], |
31
|
|
|
) { |
32
|
|
|
Assert::maxCount($proxy, C::UNBOUNDED_LIMIT); |
33
|
|
|
Assert::allIsInstanceOf($proxy, Proxy::class); |
34
|
|
|
Assert::minCount($proxy, 1, 'Missing at least one Proxy in Proxies.', MissingElementException::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return \SimpleSAML\CAS\XML\cas\Proxy[] |
40
|
|
|
*/ |
41
|
|
|
public function getProxy(): array |
42
|
|
|
{ |
43
|
|
|
return $this->proxy; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Convert XML into a Proxies-element |
49
|
|
|
* |
50
|
|
|
* @param \DOMElement $xml The XML element we should load |
51
|
|
|
* @return static |
52
|
|
|
* |
53
|
|
|
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException |
54
|
|
|
* if the qualified name of the supplied element is wrong |
55
|
|
|
* @throws \SimpleSAML\XML\Exception\MissingElementException if one of the mandatory child-elements is missing |
56
|
|
|
* @throws \SimpleSAML\XML\Exception\TooManyElementsException if too many child-elements of a type are specified |
57
|
|
|
*/ |
58
|
|
|
public static function fromXML(DOMElement $xml): static |
59
|
|
|
{ |
60
|
|
|
Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
61
|
|
|
Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); |
62
|
|
|
|
63
|
|
|
$proxy = Proxy::getChildrenOfClass($xml); |
64
|
|
|
Assert::minCount($proxy, 1, 'Missing at least one Proxy in Proxies.', MissingElementException::class); |
65
|
|
|
|
66
|
|
|
return new static($proxy); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Convert this Proxies to XML. |
72
|
|
|
* |
73
|
|
|
* @param \DOMElement|null $parent The element we should append this Proxies to. |
74
|
|
|
* @return \DOMElement |
75
|
|
|
*/ |
76
|
|
|
public function toXML(?DOMElement $parent = null): DOMElement |
77
|
|
|
{ |
78
|
|
|
$e = $this->instantiateParentElement($parent); |
79
|
|
|
|
80
|
|
|
foreach ($this->getProxy() as $proxy) { |
81
|
|
|
$proxy->toXML($e); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $e; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|