-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSpaceValue.php
More file actions
71 lines (60 loc) · 1.64 KB
/
Copy pathSpaceValue.php
File metadata and controls
71 lines (60 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace SimpleSAML\XML\Type;
use SimpleSAML\XML\Assert\Assert;
use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\XML\XML\xml\SpaceEnum;
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
use SimpleSAML\XMLSchema\Type\Builtin\NCNameValue;
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;
/**
* @package simplesaml/xml-common
*/
class SpaceValue extends NCNameValue implements AttributeTypeInterface
{
/**
* Validate the value.
*
* @param string $value
* @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
* @return void
*/
protected function validateValue(string $value): void
{
$sanitized = $this->sanitizeValue($value);
parent::validateValue($sanitized);
Assert::oneOf(
$sanitized,
[
SpaceEnum::Default->value,
SpaceEnum::Preserve->value,
],
SchemaViolationException::class,
);
}
/**
* @param \SimpleSAML\XML\XML\xml\SpaceEnum $value
* @return static
*/
public static function fromEnum(SpaceEnum $value): static
{
return new static($value->value);
}
/**
* @return \SimpleSAML\XML\XML\xml\SpaceEnum $value
*/
public function toEnum(): SpaceEnum
{
return SpaceEnum::from($this->getValue());
}
/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute
{
return new Attribute(C::NS_XML, 'xml', 'space', $this);
}
}