Cdata.php 1.4 KB

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