Float.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Sabre\VObject\Property;
  3. use
  4. Sabre\VObject\Property;
  5. /**
  6. * Float property
  7. *
  8. * This object represents FLOAT values. These can be 1 or more floating-point
  9. * numbers.
  10. *
  11. * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
  12. * @author Evert Pot (http://evertpot.com/)
  13. * @license http://sabre.io/license/ Modified BSD License
  14. */
  15. class Float extends Property {
  16. /**
  17. * In case this is a multi-value property. This string will be used as a
  18. * delimiter.
  19. *
  20. * @var string|null
  21. */
  22. public $delimiter = ';';
  23. /**
  24. * Sets a raw value coming from a mimedir (iCalendar/vCard) file.
  25. *
  26. * This has been 'unfolded', so only 1 line will be passed. Unescaping is
  27. * not yet done, but parameters are not included.
  28. *
  29. * @param string $val
  30. * @return void
  31. */
  32. public function setRawMimeDirValue($val) {
  33. $val = explode($this->delimiter, $val);
  34. foreach($val as &$item) {
  35. $item = (float)$item;
  36. }
  37. $this->setParts($val);
  38. }
  39. /**
  40. * Returns a raw mime-dir representation of the value.
  41. *
  42. * @return string
  43. */
  44. public function getRawMimeDirValue() {
  45. return implode(
  46. $this->delimiter,
  47. $this->getParts()
  48. );
  49. }
  50. /**
  51. * Returns the type of value.
  52. *
  53. * This corresponds to the VALUE= parameter. Every property also has a
  54. * 'default' valueType.
  55. *
  56. * @return string
  57. */
  58. public function getValueType() {
  59. return "FLOAT";
  60. }
  61. /**
  62. * Returns the value, in the format it should be encoded for json.
  63. *
  64. * This method must always return an array.
  65. *
  66. * @return array
  67. */
  68. public function getJsonValue() {
  69. $val = array_map(
  70. function($item) {
  71. return (float)$item;
  72. },
  73. $this->getParts()
  74. );
  75. // Special-casing the GEO property.
  76. //
  77. // See:
  78. // http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2
  79. if ($this->name==='GEO') {
  80. return array($val);
  81. } else {
  82. return $val;
  83. }
  84. }
  85. }