Skip to content

Commit ec15bc7

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

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/TypedTextContentTrait.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,40 @@
1919
*/
2020
trait TypedTextContentTrait
2121
{
22+
/** @var \SimpleSAML\XML\Type\ValueTypeInterface $content */
23+
protected ValueTypeInterface $content;
24+
25+
2226
/**
2327
* @param \SimpleSAML\XML\Type\ValueTypeInterface $content
2428
*/
2529
public function __construct(
26-
protected ValueTypeInterface $content,
30+
ValueTypeInterface $content,
2731
) {
32+
$this->setContent($content);
33+
}
34+
35+
36+
/**
37+
* Set the content of the element.
38+
*
39+
* @param \SimpleSAML\XML\Type\ValueTypeInterface $content The value to go in the XML textContent
40+
*/
41+
protected function setContent(ValueTypeInterface $content): void
42+
{
43+
Assert::isAOf($content, static::getTextContentType(), InvalidValueTypeException::class);
44+
$this->content = $content;
45+
}
46+
47+
48+
/**
49+
* Get the typed content of the element
50+
*
51+
* @return \SimpleSAML\XML\Type\ValueTypeInterface
52+
*/
53+
public function getContent(): ValueTypeInterface
54+
{
55+
return $this->content;
2856
}
2957

3058

@@ -51,17 +79,6 @@ public static function fromXML(DOMElement $xml): static
5179
}
5280

5381

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-
6582
/**
6683
* Create XML from this class
6784
*

0 commit comments

Comments
 (0)