Blame view

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