IntegerValue.php 1.7 KB

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