Base.php
1 year ago
Cdata.php
1 year ago
Elements.php
1 year ago
KeyValue.php
1 year ago
Uri.php
1 year ago
XmlFragment.php
1 year ago
Cdata.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Sabre\Xml\Element; |
| 6 | |
| 7 | use Sabre\Xml; |
| 8 | |
| 9 | /** |
| 10 | * CDATA element. |
| 11 | * |
| 12 | * This element allows you to easily inject CDATA. |
| 13 | * |
| 14 | * Note that we strongly recommend avoiding CDATA nodes, unless you definitely |
| 15 | * know what you're doing, or you're working with unchangeable systems that |
| 16 | * require CDATA. |
| 17 | * |
| 18 | * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/). |
| 19 | * @author Evert Pot (http://evertpot.com/) |
| 20 | * @license http://sabre.io/license/ Modified BSD License |
| 21 | */ |
| 22 | class Cdata implements Xml\XmlSerializable |
| 23 | { |
| 24 | /** |
| 25 | * CDATA element value. |
| 26 | */ |
| 27 | protected string $value; |
| 28 | |
| 29 | /** |
| 30 | * Constructor. |
| 31 | */ |
| 32 | public function __construct(string $value) |
| 33 | { |
| 34 | $this->value = $value; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * The xmlSerialize method is called during xml writing. |
| 39 | * |
| 40 | * Use the $writer argument to write its own xml serialization. |
| 41 | * |
| 42 | * An important note: do _not_ create a parent element. Any element |
| 43 | * implementing XmlSerializable should only ever write what's considered |
| 44 | * its 'inner xml'. |
| 45 | * |
| 46 | * The parent of the current element is responsible for writing a |
| 47 | * containing element. |
| 48 | * |
| 49 | * This allows serializers to be re-used for different element names. |
| 50 | * |
| 51 | * If you are opening new elements, you must also close them again. |
| 52 | */ |
| 53 | public function xmlSerialize(Xml\Writer $writer): void |
| 54 | { |
| 55 | $writer->writeCData($this->value); |
| 56 | } |
| 57 | } |
| 58 |