simplesamlphp /
xml-common
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace SimpleSAML\XML; |
||
| 6 | |||
| 7 | use DOMElement; |
||
| 8 | use SimpleSAML\XML\DOMDocumentFactory; |
||
| 9 | |||
| 10 | use function array_pop; |
||
| 11 | use function get_object_vars; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Trait grouping common functionality for elements implementing the SerializableElement element. |
||
| 15 | * |
||
| 16 | * @package simplesamlphp/xml-common |
||
| 17 | */ |
||
| 18 | trait SerializableElementTrait |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Whether to format the string output of this element or not. |
||
| 22 | * |
||
| 23 | * Defaults to true. Override to disable output formatting. |
||
| 24 | * |
||
| 25 | * @var bool |
||
| 26 | */ |
||
| 27 | protected bool $formatOutput = true; |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Output the class as an XML-formatted string |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public function __toString(): string |
||
| 36 | { |
||
| 37 | $xml = $this->toXML(); |
||
| 38 | |||
| 39 | $xmlString = $xml->ownerDocument->saveXML(); |
||
|
0 ignored issues
–
show
|
|||
| 40 | |||
| 41 | $doc = DOMDocumentFactory::fromString($xmlString); |
||
| 42 | $doc->formatOutput = $this->formatOutput; |
||
| 43 | |||
| 44 | if (static::getNormalization() === true) { |
||
| 45 | $normalized = DOMDocumentFactory::normalizeDocument($doc); |
||
| 46 | return $normalized->saveXML($normalized->firstChild); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $doc->saveXML($doc->firstChild); |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * Serialize this XML chunk. |
||
| 55 | * |
||
| 56 | * This method will be invoked by any calls to serialize(). |
||
| 57 | * |
||
| 58 | * @return array{0: string} The serialized representation of this XML object. |
||
| 59 | */ |
||
| 60 | public function __serialize(): array |
||
| 61 | { |
||
| 62 | $xml = $this->toXML(); |
||
| 63 | return [$xml->ownerDocument->saveXML($xml)]; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | /** |
||
| 68 | * Unserialize an XML object and load it.. |
||
| 69 | * |
||
| 70 | * This method will be invoked by any calls to unserialize(), allowing us to restore any data that might not |
||
| 71 | * be serializable in its original form (e.g.: DOM objects). |
||
| 72 | * |
||
| 73 | * @param array{0: string} $serialized The XML object that we want to restore. |
||
| 74 | */ |
||
| 75 | public function __unserialize(array $serialized): void |
||
| 76 | { |
||
| 77 | $xml = static::fromXML( |
||
| 78 | DOMDocumentFactory::fromString(array_pop($serialized))->documentElement, |
||
| 79 | ); |
||
| 80 | |||
| 81 | $vars = get_object_vars($xml); |
||
| 82 | foreach ($vars as $k => $v) { |
||
| 83 | $this->$k = $v; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | |||
| 88 | /** |
||
| 89 | * Create XML from this class |
||
| 90 | * |
||
| 91 | * @param \DOMElement|null $parent |
||
| 92 | * @return \DOMElement |
||
| 93 | */ |
||
| 94 | abstract public function toXML(?DOMElement $parent = null): DOMElement; |
||
| 95 | } |
||
| 96 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.