Boolean.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Sabre\VObject\Property;
  3. use Sabre\VObject\Property;
  4. /**
  5. * Boolean property.
  6. *
  7. * This object represents BOOLEAN values. These are always the case-insensitive
  8. * string TRUE or FALSE.
  9. *
  10. * Automatic conversion to PHP's true and false are done.
  11. *
  12. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://sabre.io/license/ Modified BSD License
  15. */
  16. class Boolean extends Property
  17. {
  18. /**
  19. * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
  20. *
  21. * This has been 'unfolded', so only 1 line will be passed. Unescaping is
  22. * not yet done, but parameters are not included.
  23. *
  24. * @param string $val
  25. */
  26. public function setRawMimeDirValue($val)
  27. {
  28. $val = 'TRUE' === strtoupper($val) ? true : false;
  29. $this->setValue($val);
  30. }
  31. /**
  32. * Returns a raw mime-dir representation of the value.
  33. *
  34. * @return string
  35. */
  36. public function getRawMimeDirValue()
  37. {
  38. return $this->value ? 'TRUE' : 'FALSE';
  39. }
  40. /**
  41. * Returns the type of value.
  42. *
  43. * This corresponds to the VALUE= parameter. Every property also has a
  44. * 'default' valueType.
  45. *
  46. * @return string
  47. */
  48. public function getValueType()
  49. {
  50. return 'BOOLEAN';
  51. }
  52. /**
  53. * Hydrate data from a XML subtree, as it would appear in a xCard or xCal
  54. * object.
  55. */
  56. public function setXmlValue(array $value)
  57. {
  58. $value = array_map(
  59. function ($value) {
  60. return 'true' === $value;
  61. },
  62. $value
  63. );
  64. parent::setXmlValue($value);
  65. }
  66. }