annotate vendor/sabre/vobject/lib/Document.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 430dbd5346f7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 * Document
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * A document is just like a component, except that it's also the top level
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 * element.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * Both a VCALENDAR and a VCARD are considered documents.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * This class also provides a registry for document types.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 abstract class Document extends Component {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 * Unknown document type
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 const UNKNOWN = 1;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 * vCalendar 1.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 const VCALENDAR10 = 2;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 * iCalendar 2.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 const ICALENDAR20 = 3;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 * vCard 2.1
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 const VCARD21 = 4;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 * vCard 3.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 const VCARD30 = 5;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 * vCard 4.0
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 const VCARD40 = 6;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 * The default name for this component.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 * This should be 'VCALENDAR' or 'VCARD'.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 * @var string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 static public $defaultName;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 * List of properties, and which classes they map to.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 static public $propertyMap = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 * List of components, along with which classes they map to.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 static public $componentMap = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 * List of value-types, and which classes they map to.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 static public $valueMap = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 * Creates a new document.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 * We're changing the default behavior slightly here. First, we don't want
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 * to have to specify a name (we already know it), and we want to allow
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 * children to be specified in the first argument.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 * But, the default behavior also works.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 * So the two sigs:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 * new Document(array $children = array(), $defaults = true);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 * new Document(string $name, array $children = array(), $defaults = true)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 public function __construct() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 $args = func_get_args();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 if (count($args)===0 || is_array($args[0])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 array_unshift($args, $this, static::$defaultName);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 call_user_func_array(array('parent', '__construct'), $args);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 array_unshift($args, $this);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105 call_user_func_array(array('parent', '__construct'), $args);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 * Returns the current document type.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 public function getDocumentType() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 return self::UNKNOWN;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 * Creates a new component or property.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 * If it's a known component, we will automatically call createComponent.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125 * otherwise, we'll assume it's a property and call createProperty instead.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 * @param string $arg1,... Unlimited number of args
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 * @return mixed
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 public function create($name) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 if (isset(static::$componentMap[strtoupper($name)])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 return call_user_func_array(array($this,'createComponent'), func_get_args());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 return call_user_func_array(array($this,'createProperty'), func_get_args());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146 * Creates a new component
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 * This method automatically searches for the correct component class, based
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 * on its name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 * You can specify the children either in key=>value syntax, in which case
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 * properties will automatically be created, or you can just pass a list of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 * Component and Property object.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 * By default, a set of sensible values will be added to the component. For
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157 * ensure that this does not happen, set $defaults to false.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 * @param array $children
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161 * @param bool $defaults
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 * @return Component
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 public function createComponent($name, array $children = null, $defaults = true) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166 $name = strtoupper($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 $class = 'Sabre\\VObject\\Component';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 if (isset(static::$componentMap[$name])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170 $class=static::$componentMap[$name];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 if (is_null($children)) $children = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 return new $class($this, $name, $children, $defaults);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 * Factory method for creating new properties
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180 * This method automatically searches for the correct property class, based
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 * on its name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 * You can specify the parameters either in key=>value syntax, in which case
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 * parameters will automatically be created, or you can just pass a list of
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185 * Parameter objects.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187 * @param string $name
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 * @param mixed $value
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 * @param array $parameters
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190 * @param string $valueType Force a specific valuetype, such as URI or TEXT
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 * @return Property
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 public function createProperty($name, $value = null, array $parameters = null, $valueType = null) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 // If there's a . in the name, it means it's prefixed by a groupname.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 if (($i=strpos($name,'.'))!==false) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 $group = substr($name, 0, $i);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 $name = strtoupper(substr($name, $i+1));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 $name = strtoupper($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201 $group = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 $class = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 if ($valueType) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207 // The valueType argument comes first to figure out the correct
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 // class.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 $class = $this->getClassNameForPropertyValue($valueType);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212 if (is_null($class) && isset($parameters['VALUE'])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 // If a VALUE parameter is supplied, we should use that.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 $class = $this->getClassNameForPropertyValue($parameters['VALUE']);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 if (is_null($class)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217 $class = $this->getClassNameForPropertyName($name);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219 if (is_null($parameters)) $parameters = array();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221 return new $class($this, $name, $value, $parameters, $group);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 * This method returns a full class-name for a value parameter.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 * For instance, DTSTART may have VALUE=DATE. In that case we will look in
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 * our valueMap table and return the appropriate class name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 * This method returns null if we don't have a specialized class.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 * @param string $valueParam
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 * @return void
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 public function getClassNameForPropertyValue($valueParam) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238 $valueParam = strtoupper($valueParam);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 if (isset(static::$valueMap[$valueParam])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240 return static::$valueMap[$valueParam];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 * Returns the default class for a property name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 * @param string $propertyName
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249 * @return string
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 public function getClassNameForPropertyName($propertyName) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 if (isset(static::$propertyMap[$propertyName])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 return static::$propertyMap[$propertyName];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 } else {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 return 'Sabre\\VObject\\Property\\Unknown';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 }