ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Document.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\VObject;
4
19abstract class Document extends Component {
20
24 const UNKNOWN = 1;
25
29 const VCALENDAR10 = 2;
30
34 const ICALENDAR20 = 3;
35
39 const VCARD21 = 4;
40
44 const VCARD30 = 5;
45
49 const VCARD40 = 6;
50
59
65 static $propertyMap = [];
66
72 static $componentMap = [];
73
79 static $valueMap = [];
80
97 function __construct() {
98
99 $args = func_get_args();
100 if (count($args) === 0 || is_array($args[0])) {
101 array_unshift($args, $this, static::$defaultName);
102 call_user_func_array(['parent', '__construct'], $args);
103 } else {
104 array_unshift($args, $this);
105 call_user_func_array(['parent', '__construct'], $args);
106 }
107
108 }
109
115 function getDocumentType() {
116
117 return self::UNKNOWN;
118
119 }
120
132 function create($name) {
133
134 if (isset(static::$componentMap[strtoupper($name)])) {
135
136 return call_user_func_array([$this, 'createComponent'], func_get_args());
137
138 } else {
139
140 return call_user_func_array([$this, 'createProperty'], func_get_args());
141
142 }
143
144 }
145
166 function createComponent($name, array $children = null, $defaults = true) {
167
168 $name = strtoupper($name);
169 $class = 'Sabre\\VObject\\Component';
170
171 if (isset(static::$componentMap[$name])) {
172 $class = static::$componentMap[$name];
173 }
174 if (is_null($children)) $children = [];
175 return new $class($this, $name, $children, $defaults);
176
177 }
178
196 function createProperty($name, $value = null, array $parameters = null, $valueType = null) {
197
198 // If there's a . in the name, it means it's prefixed by a groupname.
199 if (($i = strpos($name, '.')) !== false) {
200 $group = substr($name, 0, $i);
201 $name = strtoupper(substr($name, $i + 1));
202 } else {
203 $name = strtoupper($name);
204 $group = null;
205 }
206
207 $class = null;
208
209 if ($valueType) {
210 // The valueType argument comes first to figure out the correct
211 // class.
212 $class = $this->getClassNameForPropertyValue($valueType);
213 }
214
215 if (is_null($class)) {
216 // If a VALUE parameter is supplied, we should use that.
217 if (isset($parameters['VALUE'])) {
218 $class = $this->getClassNameForPropertyValue($parameters['VALUE']);
219 if (is_null($class)) {
220 throw new InvalidDataException('Unsupported VALUE parameter for ' . $name . ' property. You supplied "' . $parameters['VALUE'] . '"');
221 }
222 }
223 else {
224 $class = $this->getClassNameForPropertyName($name);
225 }
226 }
227 if (is_null($parameters)) $parameters = [];
228
229 return new $class($this, $name, $value, $parameters, $group);
230
231 }
232
244 function getClassNameForPropertyValue($valueParam) {
245
246 $valueParam = strtoupper($valueParam);
247 if (isset(static::$valueMap[$valueParam])) {
248 return static::$valueMap[$valueParam];
249 }
250
251 }
252
260 function getClassNameForPropertyName($propertyName) {
261
262 if (isset(static::$propertyMap[$propertyName])) {
263 return static::$propertyMap[$propertyName];
264 } else {
265 return 'Sabre\\VObject\\Property\\Unknown';
266 }
267
268 }
269
270}
An exception for terminatinating execution or to throw for unit testing.
getClassNameForPropertyName($propertyName)
Returns the default class for a property name.
Definition: Document.php:260
createComponent($name, array $children=null, $defaults=true)
Creates a new component.
Definition: Document.php:166
getDocumentType()
Returns the current document type.
Definition: Document.php:115
__construct()
Creates a new document.
Definition: Document.php:97
const VCARD30
vCard 3.0.
Definition: Document.php:44
createProperty($name, $value=null, array $parameters=null, $valueType=null)
Factory method for creating new properties.
Definition: Document.php:196
const UNKNOWN
Unknown document type.
Definition: Document.php:24
getClassNameForPropertyValue($valueParam)
This method returns a full class-name for a value parameter.
Definition: Document.php:244
const ICALENDAR20
iCalendar 2.0.
Definition: Document.php:34
const VCARD21
vCard 2.1.
Definition: Document.php:39
const VCALENDAR10
vCalendar 1.0.
Definition: Document.php:29
create($name)
Creates a new component or property.
Definition: Document.php:132
const VCARD40
vCard 4.0.
Definition: Document.php:49
This exception is thrown whenever an invalid value is found anywhere in a iCalendar or vCard object.
count()
Returns the number of elements.
Definition: Node.php:177
$i
Definition: disco.tpl.php:19