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