diff options
Diffstat (limited to 'vendor/sabre/xml/lib/Element/XmlFragment.php')
-rw-r--r-- | vendor/sabre/xml/lib/Element/XmlFragment.php | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/vendor/sabre/xml/lib/Element/XmlFragment.php b/vendor/sabre/xml/lib/Element/XmlFragment.php index 642241ca4..413e0f106 100644 --- a/vendor/sabre/xml/lib/Element/XmlFragment.php +++ b/vendor/sabre/xml/lib/Element/XmlFragment.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + namespace Sabre\Xml\Element; use Sabre\Xml\Element; @@ -20,20 +22,29 @@ use Sabre\Xml\Writer; * 3. It will have all the relevant xmlns attributes. * 4. It may not have a root element. */ -class XmlFragment implements Element { - +class XmlFragment implements Element +{ + /** + * The inner XML value. + * + * @var string + */ protected $xml; - function __construct($xml) { - + /** + * Constructor. + */ + public function __construct(string $xml) + { $this->xml = $xml; - } - function getXml() { - + /** + * Returns the inner XML document. + */ + public function getXml(): string + { return $this->xml; - } /** @@ -51,12 +62,9 @@ class XmlFragment implements Element { * This allows serializers to be re-used for different element names. * * If you are opening new elements, you must also close them again. - * - * @param Writer $writer - * @return void */ - function xmlSerialize(Writer $writer) { - + public function xmlSerialize(Writer $writer) + { $reader = new Reader(); // Wrapping the xml in a container, so root-less values can still be @@ -69,28 +77,26 @@ XML; $reader->xml($xml); while ($reader->read()) { - if ($reader->depth < 1) { // Skipping the root node. continue; } switch ($reader->nodeType) { - - case Reader::ELEMENT : + case Reader::ELEMENT: $writer->startElement( $reader->getClark() ); $empty = $reader->isEmptyElement; while ($reader->moveToNextAttribute()) { switch ($reader->namespaceURI) { - case '' : + case '': $writer->writeAttribute($reader->localName, $reader->value); break; - case 'http://www.w3.org/2000/xmlns/' : + case 'http://www.w3.org/2000/xmlns/': // Skip namespace declarations break; - default : + default: $writer->writeAttribute($reader->getClark(), $reader->value); break; } @@ -99,20 +105,17 @@ XML; $writer->endElement(); } break; - case Reader::CDATA : - case Reader::TEXT : + case Reader::CDATA: + case Reader::TEXT: $writer->text( $reader->value ); break; - case Reader::END_ELEMENT : + case Reader::END_ELEMENT: $writer->endElement(); break; - } - } - } /** @@ -133,15 +136,13 @@ XML; * $reader->parseInnerTree() will parse the entire sub-tree, and advance to * the next element. * - * @param Reader $reader * @return mixed */ - static function xmlDeserialize(Reader $reader) { - + public static function xmlDeserialize(Reader $reader) + { $result = new self($reader->readInnerXml()); $reader->next(); - return $result; + return $result; } - } |