annotate plugins/libcalendaring/lib/Sabre/VObject/Document.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 * Document
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * A document is just like a component, except that it's also the top level
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * element.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * Both a VCALENDAR and a VCARD are considered documents.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * This class also provides a registry for document types.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * @copyright Copyright (C) 2007-2013 fruux GmbH. All rights reserved.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 abstract class Document extends Component {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * The default name for this component.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * This should be 'VCALENDAR' or 'VCARD'.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 * @var string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 static $defaultName;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 * Creates a new document.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 * We're changing the default behavior slightly here. First, we don't want
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 * to have to specify a name (we already know it), and we want to allow
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 * children to be specified in the first argument.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 * But, the default behavior also works.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 * So the two sigs:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 * new Document(array $children = array());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 * new Document(string $name, array $children = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 public function __construct() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 $args = func_get_args();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 if (count($args)===0 || is_array($args[0])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 array_unshift($args, static::$defaultName);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 call_user_func_array(array('parent', '__construct'), $args);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 call_user_func_array(array('parent', '__construct'), $args);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 * Creates a new component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 * This method automatically searches for the correct component class, based
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 * on its name.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 * You can specify the children either in key=>value syntax, in which case
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 * properties will automatically be created, or you can just pass a list of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 * Component and Property object.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 * @param array $children
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 * @return Component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 public function createComponent($name, array $children = array()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 $component = Component::create($name);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 foreach($children as $k=>$v) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 if ($v instanceof Node) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 $component->add($v);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 $component->add($k, $v);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 return $component;
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
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 * Factory method for creating new properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 * This method automatically searches for the correct property class, based
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 * on its name.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 * You can specify the parameters either in key=>value syntax, in which case
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 * parameters will automatically be created, or you can just pass a list of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 * Parameter objects.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 * @param string $name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 * @param mixed $value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 * @param array $parameters
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101 * @return Property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 public function createProperty($name, $value = null, array $parameters = array()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 return Property::create($name, $value, $parameters);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 }