Mercurial > hg > rc1
comparison plugins/libcalendaring/lib/Sabre/VObject/Parameter.php @ 4:888e774ee983
libcalendar plugin as distributed
| author | Charlie Root |
|---|---|
| date | Sat, 13 Jan 2018 08:57:56 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:f6fe4b6ae66a | 4:888e774ee983 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Sabre\VObject; | |
| 4 | |
| 5 /** | |
| 6 * VObject Parameter | |
| 7 * | |
| 8 * This class represents a parameter. A parameter is always tied to a property. | |
| 9 * In the case of: | |
| 10 * DTSTART;VALUE=DATE:20101108 | |
| 11 * VALUE=DATE would be the parameter name and value. | |
| 12 * | |
| 13 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/). | |
| 14 * @author Evert Pot (http://evertpot.com/) | |
| 15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License | |
| 16 */ | |
| 17 class Parameter extends Node { | |
| 18 | |
| 19 /** | |
| 20 * Parameter name | |
| 21 * | |
| 22 * @var string | |
| 23 */ | |
| 24 public $name; | |
| 25 | |
| 26 /** | |
| 27 * Parameter value | |
| 28 * | |
| 29 * @var string | |
| 30 */ | |
| 31 public $value; | |
| 32 | |
| 33 /** | |
| 34 * Sets up the object | |
| 35 * | |
| 36 * @param string $name | |
| 37 * @param string $value | |
| 38 */ | |
| 39 public function __construct($name, $value = null) { | |
| 40 | |
| 41 if (!is_scalar($value) && !is_null($value)) { | |
| 42 throw new \InvalidArgumentException('The value argument must be a scalar value or null'); | |
| 43 } | |
| 44 | |
| 45 $this->name = strtoupper($name); | |
| 46 $this->value = $value; | |
| 47 | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * Returns the parameter's internal value. | |
| 52 * | |
| 53 * @return string | |
| 54 */ | |
| 55 public function getValue() { | |
| 56 | |
| 57 return $this->value; | |
| 58 | |
| 59 } | |
| 60 | |
| 61 | |
| 62 /** | |
| 63 * Turns the object back into a serialized blob. | |
| 64 * | |
| 65 * @return string | |
| 66 */ | |
| 67 public function serialize() { | |
| 68 | |
| 69 if (is_null($this->value)) { | |
| 70 return $this->name; | |
| 71 } | |
| 72 $src = array( | |
| 73 '\\', | |
| 74 "\n", | |
| 75 ); | |
| 76 $out = array( | |
| 77 '\\\\', | |
| 78 '\n', | |
| 79 ); | |
| 80 | |
| 81 // quote parameters according to RFC 5545, Section 3.2 | |
| 82 $quotes = ''; | |
| 83 if (preg_match('/[:;,]/', $this->value)) { | |
| 84 $quotes = '"'; | |
| 85 } | |
| 86 | |
| 87 return $this->name . '=' . $quotes . str_replace($src, $out, $this->value) . $quotes; | |
| 88 | |
| 89 } | |
| 90 | |
| 91 /** | |
| 92 * Called when this object is being cast to a string | |
| 93 * | |
| 94 * @return string | |
| 95 */ | |
| 96 public function __toString() { | |
| 97 | |
| 98 return $this->value; | |
| 99 | |
| 100 } | |
| 101 | |
| 102 } |
