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