1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LightSAML-Core package. |
5
|
|
|
* |
6
|
|
|
* (c) Milos Tomic <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace LightSaml\Model\Assertion; |
13
|
|
|
|
14
|
|
|
use LightSaml\Model\Context\DeserializationContext; |
15
|
|
|
use LightSaml\Model\Context\SerializationContext; |
16
|
|
|
use LightSaml\SamlConstants; |
17
|
|
|
|
18
|
|
|
class AttributeStatement extends AbstractStatement |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Attribute[] |
22
|
|
|
*/ |
23
|
|
|
protected $attributes = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return AttributeStatement |
27
|
|
|
*/ |
28
|
|
|
public function addAttribute(Attribute $attribute) |
29
|
|
|
{ |
30
|
|
|
$this->attributes[] = $attribute; |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return \LightSaml\Model\Assertion\Attribute[] |
37
|
|
|
*/ |
38
|
|
|
public function getAllAttributes() |
39
|
|
|
{ |
40
|
|
|
return $this->attributes; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $name |
45
|
|
|
* |
46
|
|
|
* @return Attribute|null |
47
|
|
|
*/ |
48
|
|
|
public function getFirstAttributeByName($name) |
49
|
|
|
{ |
50
|
|
|
if (is_array($this->getAllAttributes())) { |
|
|
|
|
51
|
|
|
foreach ($this->getAllAttributes() as $attribute) { |
52
|
|
|
if (null == $name || $attribute->getName() == $name) { |
53
|
|
|
return $attribute; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function serialize(\DOMNode $parent, SerializationContext $context) |
65
|
|
|
{ |
66
|
|
|
$result = $this->createElement('AttributeStatement', SamlConstants::NS_ASSERTION, $parent, $context); |
67
|
|
|
|
68
|
|
|
$this->manyElementsToXml($this->getAllAttributes(), $result, $context, null); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function deserialize(\DOMNode $node, DeserializationContext $context) |
72
|
|
|
{ |
73
|
|
|
$this->checkXmlNodeName($node, 'AttributeStatement', SamlConstants::NS_ASSERTION); |
74
|
|
|
|
75
|
|
|
$this->attributes = []; |
76
|
|
|
$this->manyElementsFromXml( |
77
|
|
|
$node, |
78
|
|
|
$context, |
79
|
|
|
'Attribute', |
80
|
|
|
'saml', |
81
|
|
|
'LightSaml\Model\Assertion\Attribute', |
82
|
|
|
'addAttribute' |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|