ScheduleCalendarTransp.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\CalDAV\Xml\Property;
  4. use Sabre\CalDAV\Plugin;
  5. use Sabre\Xml\Deserializer;
  6. use Sabre\Xml\Element;
  7. use Sabre\Xml\Reader;
  8. use Sabre\Xml\Writer;
  9. /**
  10. * schedule-calendar-transp property.
  11. *
  12. * This property is a representation of the schedule-calendar-transp property.
  13. * This property is defined in:
  14. *
  15. * http://tools.ietf.org/html/rfc6638#section-9.1
  16. *
  17. * Its values are either 'transparent' or 'opaque'. If it's transparent, it
  18. * means that this calendar will not be taken into consideration when a
  19. * different user queries for free-busy information. If it's 'opaque', it will.
  20. *
  21. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  22. * @author Evert Pot (http://www.rooftopsolutions.nl/)
  23. * @license http://sabre.io/license/ Modified BSD License
  24. */
  25. class ScheduleCalendarTransp implements Element
  26. {
  27. const TRANSPARENT = 'transparent';
  28. const OPAQUE = 'opaque';
  29. /**
  30. * value.
  31. *
  32. * @var string
  33. */
  34. protected $value;
  35. /**
  36. * Creates the property.
  37. *
  38. * @param string $value
  39. */
  40. public function __construct($value)
  41. {
  42. if (self::TRANSPARENT !== $value && self::OPAQUE !== $value) {
  43. throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"');
  44. }
  45. $this->value = $value;
  46. }
  47. /**
  48. * Returns the current value.
  49. *
  50. * @return string
  51. */
  52. public function getValue()
  53. {
  54. return $this->value;
  55. }
  56. /**
  57. * The xmlSerialize method is called during xml writing.
  58. *
  59. * Use the $writer argument to write its own xml serialization.
  60. *
  61. * An important note: do _not_ create a parent element. Any element
  62. * implementing XmlSerializable should only ever write what's considered
  63. * its 'inner xml'.
  64. *
  65. * The parent of the current element is responsible for writing a
  66. * containing element.
  67. *
  68. * This allows serializers to be re-used for different element names.
  69. *
  70. * If you are opening new elements, you must also close them again.
  71. */
  72. public function xmlSerialize(Writer $writer)
  73. {
  74. switch ($this->value) {
  75. case self::TRANSPARENT:
  76. $writer->writeElement('{'.Plugin::NS_CALDAV.'}transparent');
  77. break;
  78. case self::OPAQUE:
  79. $writer->writeElement('{'.Plugin::NS_CALDAV.'}opaque');
  80. break;
  81. }
  82. }
  83. /**
  84. * The deserialize method is called during xml parsing.
  85. *
  86. * This method is called statically, this is because in theory this method
  87. * may be used as a type of constructor, or factory method.
  88. *
  89. * Often you want to return an instance of the current class, but you are
  90. * free to return other data as well.
  91. *
  92. * You are responsible for advancing the reader to the next element. Not
  93. * doing anything will result in a never-ending loop.
  94. *
  95. * If you just want to skip parsing for this element altogether, you can
  96. * just call $reader->next();
  97. *
  98. * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
  99. * the next element.
  100. *
  101. * @return mixed
  102. */
  103. public static function xmlDeserialize(Reader $reader)
  104. {
  105. $elems = Deserializer\enum($reader, Plugin::NS_CALDAV);
  106. if (in_array('transparent', $elems)) {
  107. $value = self::TRANSPARENT;
  108. } else {
  109. $value = self::OPAQUE;
  110. }
  111. return new self($value);
  112. }
  113. }