1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\md; |
6
|
|
|
|
7
|
|
|
use SimpleSAML\SAML2\Assert\Assert; |
8
|
|
|
use SimpleSAML\SAML2\Exception\ArrayValidationException; |
9
|
|
|
use SimpleSAML\SAML2\Type\EmailAddressValue; |
10
|
|
|
use SimpleSAML\XML\{ |
11
|
|
|
ArrayizableElementInterface, |
12
|
|
|
SchemaValidatableElementInterface, |
13
|
|
|
SchemaValidatableElementTrait, |
14
|
|
|
TypedTextContentTrait, |
15
|
|
|
}; |
16
|
|
|
|
17
|
|
|
use function array_key_first; |
18
|
|
|
use function preg_filter; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class implementing EmailAddress. |
22
|
|
|
* |
23
|
|
|
* @package simplesamlphp/saml2 |
24
|
|
|
*/ |
25
|
|
|
final class EmailAddress extends AbstractMdElement implements |
26
|
|
|
ArrayizableElementInterface, |
27
|
|
|
SchemaValidatableElementInterface |
28
|
|
|
{ |
29
|
|
|
use SchemaValidatableElementTrait; |
30
|
|
|
use TypedTextContentTrait; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
public const TEXTCONTENT_TYPE = EmailAddressValue::class; |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the content of the element. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function getContent(): string |
42
|
|
|
{ |
43
|
|
|
return preg_filter('/^/', 'mailto:', $this->content->getValue()); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a class from an array |
49
|
|
|
* |
50
|
|
|
* @param array $data |
51
|
|
|
* @return static |
52
|
|
|
*/ |
53
|
|
|
public static function fromArray(array $data): static |
54
|
|
|
{ |
55
|
|
|
Assert::allString($data, ArrayValidationException::class); |
56
|
|
|
|
57
|
|
|
$index = array_key_first($data); |
58
|
|
|
return new static( |
59
|
|
|
EmailAddressValue::fromString($data[$index]), |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Create an array from this class |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function toArray(): array |
70
|
|
|
{ |
71
|
|
|
return [$this->getContent()]; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|