Skip to content

Commit 0e4242e

Browse files
committed
Improve re-usability of the TypedTextContentTrait
1 parent fd73d4b commit 0e4242e

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/TypedTextContentTrait.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,34 @@ trait TypedTextContentTrait
2323
* @param \SimpleSAML\XML\Type\ValueTypeInterface $content
2424
*/
2525
public function __construct(
26-
protected ValueTypeInterface $content,
26+
protected ValueTypeValue $content,
2727
) {
2828
}
2929

3030

31+
/**
32+
* Set the content of the element.
33+
*
34+
* @param \SimpleSAML\XML\Type\ValueTypeInterface $content The value to go in the XML textContent
35+
*/
36+
protected function setContent(ValueTypeInterface $content): void
37+
{
38+
Assert::isAOf($content, static::getTextContentType(), InvalidValueTypeException::class);
39+
$this->content = $content;
40+
}
41+
42+
43+
/**
44+
* Get the typed content of the element
45+
*
46+
* @return \SimpleSAML\XML\Type\ValueTypeInterface
47+
*/
48+
public function getContent(): ValueTypeInterface
49+
{
50+
return $this->content;
51+
}
52+
53+
3154
/**
3255
* Create a class from XML
3356
*
@@ -51,17 +74,6 @@ public static function fromXML(DOMElement $xml): static
5174
}
5275

5376

54-
/**
55-
* Get the typed content of the element
56-
*
57-
* @return \SimpleSAML\XML\Type\ValueTypeInterface
58-
*/
59-
public function getContent(): ValueTypeInterface
60-
{
61-
return $this->content;
62-
}
63-
64-
6577
/**
6678
* Create XML from this class
6779
*

0 commit comments

Comments
 (0)