ICalendar
6 months ago
VCard
6 months ago
Binary.php
6 months ago
Boolean.php
6 months ago
FlatText.php
6 months ago
FloatValue.php
6 months ago
IntegerValue.php
6 months ago
Text.php
6 months ago
Time.php
6 months ago
Unknown.php
6 months ago
Uri.php
6 months ago
UtcOffset.php
6 months ago
FloatValue.php
125 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaVendor\Sabre\VObject\Property; |
| 4 | |
| 5 | use AmeliaVendor\Sabre\VObject\Property; |
| 6 | use AmeliaVendor\Sabre\Xml; |
| 7 | |
| 8 | /** |
| 9 | * Float property. |
| 10 | * |
| 11 | * This object represents FLOAT values. These can be 1 or more floating-point |
| 12 | * numbers. |
| 13 | * |
| 14 | * @copyright Copyright (C) fruux GmbH (https://fruux.com/) |
| 15 | * @author Evert Pot (http://evertpot.com/) |
| 16 | * @license http://sabre.io/license/ Modified BSD License |
| 17 | */ |
| 18 | class FloatValue extends Property |
| 19 | { |
| 20 | /** |
| 21 | * In case this is a multi-value property. This string will be used as a |
| 22 | * delimiter. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | public $delimiter = ';'; |
| 27 | |
| 28 | /** |
| 29 | * Sets a raw value coming from a mimedir (iCalendar/vCard) file. |
| 30 | * |
| 31 | * This has been 'unfolded', so only 1 line will be passed. Unescaping is |
| 32 | * not yet done, but parameters are not included. |
| 33 | * |
| 34 | * @param string $val |
| 35 | */ |
| 36 | public function setRawMimeDirValue($val) |
| 37 | { |
| 38 | $val = explode($this->delimiter, $val); |
| 39 | foreach ($val as &$item) { |
| 40 | $item = (float) $item; |
| 41 | } |
| 42 | $this->setParts($val); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns a raw mime-dir representation of the value. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function getRawMimeDirValue() |
| 51 | { |
| 52 | return implode( |
| 53 | $this->delimiter, |
| 54 | $this->getParts() |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the type of value. |
| 60 | * |
| 61 | * This corresponds to the VALUE= parameter. Every property also has a |
| 62 | * 'default' valueType. |
| 63 | * |
| 64 | * @return string |
| 65 | */ |
| 66 | public function getValueType() |
| 67 | { |
| 68 | return 'FLOAT'; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Returns the value, in the format it should be encoded for JSON. |
| 73 | * |
| 74 | * This method must always return an array. |
| 75 | * |
| 76 | * @return array |
| 77 | */ |
| 78 | public function getJsonValue() |
| 79 | { |
| 80 | $val = array_map('floatval', $this->getParts()); |
| 81 | |
| 82 | // Special-casing the GEO property. |
| 83 | // |
| 84 | // See: |
| 85 | // http://tools.ietf.org/html/draft-ietf-jcardcal-jcal-04#section-3.4.1.2 |
| 86 | if ('GEO' === $this->name) { |
| 87 | return [$val]; |
| 88 | } |
| 89 | |
| 90 | return $val; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Hydrate data from a XML subtree, as it would appear in a xCard or xCal |
| 95 | * object. |
| 96 | */ |
| 97 | public function setXmlValue(array $value) |
| 98 | { |
| 99 | $value = array_map('floatval', $value); |
| 100 | parent::setXmlValue($value); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * This method serializes only the value of a property. This is used to |
| 105 | * create xCard or xCal documents. |
| 106 | * |
| 107 | * @param Xml\Writer $writer XML writer |
| 108 | */ |
| 109 | protected function xmlSerializeValue(Xml\Writer $writer) |
| 110 | { |
| 111 | // Special-casing the GEO property. |
| 112 | // |
| 113 | // See: |
| 114 | // http://tools.ietf.org/html/rfc6321#section-3.4.1.2 |
| 115 | if ('GEO' === $this->name) { |
| 116 | $value = array_map('floatval', $this->getParts()); |
| 117 | |
| 118 | $writer->writeElement('latitude', $value[0]); |
| 119 | $writer->writeElement('longitude', $value[1]); |
| 120 | } else { |
| 121 | parent::xmlSerializeValue($writer); |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 |