ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Component Class Reference

Component. More...

+ Inheritance diagram for Sabre\VObject\Component:
+ Collaboration diagram for Sabre\VObject\Component:

Public Member Functions

 __construct (Document $root, $name, array $children=[], $defaults=true)
 Creates a new component. More...
 
 add ()
 Adds a new property or component, and returns the new item. More...
 
 remove ($item)
 This method removes a component or property from this component. More...
 
 children ()
 Returns a flat list of all the properties and components in this component. More...
 
 getComponents ()
 This method only returns a list of sub-components. More...
 
 select ($name)
 Returns an array with elements that match the specified name. More...
 
 serialize ()
 Turns the object back into a serialized blob. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 __isset ($name)
 This method checks if a sub-element with the specified name exists. More...
 
 __set ($name, $value)
 Using the setter method you can add properties or subcomponents. More...
 
 __unset ($name)
 Removes all properties and components within this component with the specified name. More...
 
 __clone ()
 This method is automatically called when the object is cloned. More...
 
 getValidationRules ()
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 destroy ()
 Call this method on a document if you're done using it. More...
 
- Public Member Functions inherited from Sabre\VObject\Node
 serialize ()
 Serializes the node into a mimedir format. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 destroy ()
 Call this method on a document if you're done using it. More...
 
 getIterator ()
 Returns the iterator for this object. More...
 
 setIterator (ElementList $iterator)
 Sets the overridden iterator. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 count ()
 Returns the number of elements. More...
 
 offsetExists ($offset)
 Checks if an item exists through ArrayAccess. More...
 
 offsetGet ($offset)
 Gets an item through ArrayAccess. More...
 
 offsetSet ($offset, $value)
 Sets an item through ArrayAccess. More...
 
 offsetUnset ($offset)
 Sets an item through ArrayAccess. More...
 
- Public Member Functions inherited from Sabre\Xml\XmlSerializable
 xmlSerialize (Writer $writer)
 The xmlSerialize method is called during xml writing. More...
 

Data Fields

 $name
 
- Data Fields inherited from Sabre\VObject\Node
const REPAIR = 1
 The following constants are used by the validate() method. More...
 
const PROFILE_CARDDAV = 2
 If this option is set, the validator will operate on the vcards on the assumption that the vcards need to be valid for CardDAV. More...
 
const PROFILE_CALDAV = 4
 If this option is set, the validator will operate on iCalendar objects on the assumption that the vcards need to be valid for CalDAV. More...
 
 $parent
 

Protected Member Functions

 getDefaults ()
 This method should return a list of default property values. More...
 

Protected Attributes

 $children = []
 
- Protected Attributes inherited from Sabre\VObject\Node
 $iterator = null
 
 $root
 

Detailed Description

Component.

A component represents a group of properties, such as VCALENDAR, VEVENT, or VCARD.

Author
Evert Pot (http://evertpot.com/) @license http://sabre.io/license/ Modified BSD License

Definition at line 17 of file Component.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\Component::__construct ( Document  $root,
  $name,
array  $children = [],
  $defaults = true 
)

Creates a new component.

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.

By default, a set of sensible values will be added to the component. For an iCalendar object, this may be something like CALSCALE:GREGORIAN. To ensure that this does not happen, set $defaults to false.

Parameters
Document$root
string$namesuch as VCALENDAR, VEVENT.
array$children
bool$defaults
Returns
void

Definition at line 53 of file Component.php.

53 {
54
55 $this->name = strtoupper($name);
56 $this->root = $root;
57
58 if ($defaults) {
59 // This is a terribly convoluted way to do this, but this ensures
60 // that the order of properties as they are specified in both
61 // defaults and the childrens list, are inserted in the object in a
62 // natural way.
63 $list = $this->getDefaults();
64 $nodes = [];
65 foreach ($children as $key => $value) {
66 if ($value instanceof Node) {
67 if (isset($list[$value->name])) {
68 unset($list[$value->name]);
69 }
70 $nodes[] = $value;
71 } else {
72 $list[$key] = $value;
73 }
74 }
75 foreach ($list as $key => $value) {
76 $this->add($key, $value);
77 }
78 foreach ($nodes as $node) {
79 $this->add($node);
80 }
81 } else {
82 foreach ($children as $k => $child) {
83 if ($child instanceof Node) {
84 // Component or Property
85 $this->add($child);
86 } else {
87
88 // Property key=>value
89 $this->add($k, $child);
90 }
91 }
92 }
93
94 }
add()
Adds a new property or component, and returns the new item.
Definition: Component.php:109
getDefaults()
This method should return a list of default property values.
Definition: Component.php:440
A node is the root class for every element in an iCalendar of vCard object.
Definition: Node.php:19
$key
Definition: croninfo.php:18
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41

References Sabre\VObject\Component\$children, $key, $list, Sabre\VObject\Component\$name, $nodes, Sabre\VObject\Node\$root, Sabre\VObject\Component\add(), and Sabre\VObject\Component\getDefaults().

+ Here is the call graph for this function:

Member Function Documentation

◆ __clone()

Sabre\VObject\Component::__clone ( )

This method is automatically called when the object is cloned.

Specifically, this will ensure all child elements are also cloned.

Returns
void

Definition at line 543 of file Component.php.

543 {
544
545 foreach ($this->children as $childName => $childGroup) {
546 foreach ($childGroup as $key => $child) {
547 $clonedChild = clone $child;
548 $clonedChild->parent = $this;
549 $clonedChild->root = $this->root;
550 $this->children[$childName][$key] = $clonedChild;
551 }
552 }
553
554 }
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187

References $key, Sabre\VObject\Node\$root, and Sabre\VObject\Component\children().

+ Here is the call graph for this function:

◆ __isset()

Sabre\VObject\Component::__isset (   $name)

This method checks if a sub-element with the specified name exists.

Parameters
string$name
Returns
bool

Definition at line 489 of file Component.php.

489 {
490
491 $matches = $this->select($name);
492 return count($matches) > 0;
493
494 }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
count()
Returns the number of elements.
Definition: Node.php:177

References Sabre\VObject\Component\$name, Sabre\VObject\Node\count(), and Sabre\VObject\Component\select().

+ Here is the call graph for this function:

◆ __set()

Sabre\VObject\Component::__set (   $name,
  $value 
)

Using the setter method you can add properties or subcomponents.

You can either pass a Component, Property object, or a string to automatically create a Property.

If the item already exists, it will be removed. If you want to add a new item with the same name, always use the add() method.

Parameters
string$name
mixed$value
Returns
void

Definition at line 510 of file Component.php.

510 {
511
512 $name = strtoupper($name);
513 $this->remove($name);
514 if ($value instanceof self || $value instanceof Property) {
515 $this->add($value);
516 } else {
517 $this->add($name, $value);
518 }
519 }

References Sabre\VObject\Component\$name, and Sabre\VObject\Component\add().

+ Here is the call graph for this function:

◆ __unset()

Sabre\VObject\Component::__unset (   $name)

Removes all properties and components within this component with the specified name.

Parameters
string$name
Returns
void

Definition at line 529 of file Component.php.

529 {
530
531 $this->remove($name);
532
533 }

References Sabre\VObject\Component\$name.

◆ add()

Sabre\VObject\Component::add ( )

Adds a new property or component, and returns the new item.

This method has 3 possible signatures:

add(Component $comp) // Adds a new component add(Property $prop) // Adds a new property add($name, $value, array $parameters = []) // Adds a new property add($name, array $children = []) // Adds a new component by name.

Returns
Node

Definition at line 109 of file Component.php.

109 {
110
111 $arguments = func_get_args();
112
113 if ($arguments[0] instanceof Node) {
114 if (isset($arguments[1])) {
115 throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject Node');
116 }
117 $arguments[0]->parent = $this;
118 $newNode = $arguments[0];
119
120 } elseif (is_string($arguments[0])) {
121
122 $newNode = call_user_func_array([$this->root, 'create'], $arguments);
123
124 } else {
125
126 throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string');
127
128 }
129
130 $name = $newNode->name;
131 if (isset($this->children[$name])) {
132 $this->children[$name][] = $newNode;
133 } else {
134 $this->children[$name] = [$newNode];
135 }
136 return $newNode;
137
138 }

References Sabre\VObject\Component\$name, and Sabre\VObject\Component\children().

Referenced by Sabre\VObject\Component\__construct(), Sabre\VObject\Component\__set(), Sabre\VObject\Parser\XML\createProperty(), Sabre\VObject\Parser\XML\parseComponent(), and Sabre\VObject\Component\validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ children()

Sabre\VObject\Component::children ( )

◆ destroy()

Sabre\VObject\Component::destroy ( )

Call this method on a document if you're done using it.

It's intended to remove all circular references, so PHP can easily clean it up.

Returns
void

Reimplemented from Sabre\VObject\Node.

Definition at line 703 of file Component.php.

703 {
704
705 parent::destroy();
706 foreach ($this->children as $childGroup) {
707 foreach ($childGroup as $child) {
708 $child->destroy();
709 }
710 }
711 $this->children = [];
712
713 }

References Sabre\VObject\Component\children().

+ Here is the call graph for this function:

◆ getComponents()

Sabre\VObject\Component::getComponents ( )

This method only returns a list of sub-components.

Properties are ignored.

Returns
array

Definition at line 203 of file Component.php.

203 {
204
205 $result = [];
206
207 foreach ($this->children as $childGroup) {
208 foreach ($childGroup as $child) {
209 if ($child instanceof self) {
210 $result[] = $child;
211 }
212 }
213 }
214 return $result;
215
216 }

References $result, and Sabre\VObject\Component\children().

+ Here is the call graph for this function:

◆ getDefaults()

Sabre\VObject\Component::getDefaults ( )
protected

This method should return a list of default property values.

Returns
array

Reimplemented in Sabre\VObject\Component\VCalendar, Sabre\VObject\Component\VCard, Sabre\VObject\Component\VEvent, Sabre\VObject\Component\VJournal, Sabre\VObject\Component\VTodo, and Sabre\VObject\FakeComponent.

Definition at line 440 of file Component.php.

440 {
441
442 return [];
443
444 }

Referenced by Sabre\VObject\Component\__construct(), and Sabre\VObject\Component\validate().

+ Here is the caller graph for this function:

◆ getValidationRules()

◆ jsonSerialize()

Sabre\VObject\Component::jsonSerialize ( )

This method returns an array, with the representation as it should be encoded in JSON.

This is used to create jCard or jCal documents.

Returns
array

Reimplemented from Sabre\VObject\Node.

Reimplemented in Sabre\VObject\Component\VCard.

Definition at line 360 of file Component.php.

360 {
361
362 $components = [];
363 $properties = [];
364
365 foreach ($this->children as $childGroup) {
366 foreach ($childGroup as $child) {
367 if ($child instanceof self) {
368 $components[] = $child->jsonSerialize();
369 } else {
370 $properties[] = $child->jsonSerialize();
371 }
372 }
373 }
374
375 return [
376 strtolower($this->name),
377 $properties,
378 $components
379 ];
380
381 }

References Sabre\VObject\Component\children().

+ Here is the call graph for this function:

◆ remove()

Sabre\VObject\Component::remove (   $item)

This method removes a component or property from this component.

You can either specify the item by name (like DTSTART), in which case all properties/components with that name will be removed, or you can pass an instance of a property or component, in which case only that exact item will be removed.

Parameters
string | Property | Component$item
Returns
void

Definition at line 151 of file Component.php.

151 {
152
153 if (is_string($item)) {
154 // If there's no dot in the name, it's an exact property name and
155 // we can just wipe out all those properties.
156 //
157 if (strpos($item, '.') === false) {
158 unset($this->children[strtoupper($item)]);
159 return;
160 }
161 // If there was a dot, we need to ask select() to help us out and
162 // then we just call remove recursively.
163 foreach ($this->select($item) as $child) {
164
165 $this->remove($child);
166
167 }
168 } else {
169 foreach ($this->select($item->name) as $k => $child) {
170 if ($child === $item) {
171 unset($this->children[$item->name][$k]);
172 return;
173 }
174 }
175 }
176
177 throw new \InvalidArgumentException('The item you passed to remove() was not a child of this component');
178
179 }

References Sabre\VObject\Component\children(), and Sabre\VObject\Component\select().

+ Here is the call graph for this function:

◆ select()

Sabre\VObject\Component::select (   $name)

Returns an array with elements that match the specified name.

This function is also aware of MIME-Directory groups (as they appear in vcards). This means that if a property is grouped as "HOME.EMAIL", it will also be returned when searching for just "EMAIL". If you want to search for a property in a specific group, you can select on the entire string ("HOME.EMAIL"). If you want to search on a specific property that has not been assigned a group, specify ".EMAIL".

Parameters
string$name
Returns
array

Definition at line 231 of file Component.php.

231 {
232
233 $group = null;
234 $name = strtoupper($name);
235 if (strpos($name, '.') !== false) {
236 list($group, $name) = explode('.', $name, 2);
237 }
238 if ($name === '') $name = null;
239
240 if (!is_null($name)) {
241
242 $result = isset($this->children[$name]) ? $this->children[$name] : [];
243
244 if (is_null($group)) {
245 return $result;
246 } else {
247 // If we have a group filter as well, we need to narrow it down
248 // more.
249 return array_filter(
250 $result,
251 function($child) use ($group) {
252
253 return $child instanceof Property && strtoupper($child->group) === $group;
254
255 }
256 );
257 }
258
259 }
260
261 // If we got to this point, it means there was no 'name' specified for
262 // searching, implying that this is a group-only search.
263 $result = [];
264 foreach ($this->children as $childGroup) {
265
266 foreach ($childGroup as $child) {
267
268 if ($child instanceof Property && strtoupper($child->group) === $group) {
269 $result[] = $child;
270 }
271
272 }
273
274 }
275 return $result;
276
277 }

References Sabre\VObject\Component\$name, $result, and Sabre\VObject\Component\children().

Referenced by Sabre\VObject\Component\__isset(), Sabre\VObject\Component\VCard\getByType(), Sabre\VObject\Component\VFreeBusy\isFree(), Sabre\VObject\Component\VCard\preferred(), Sabre\VObject\Component\remove(), Sabre\VObject\Component\validate(), and Sabre\VObject\Component\VCard\validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serialize()

Sabre\VObject\Component::serialize ( )

Turns the object back into a serialized blob.

Returns
string

Gives a component a 'score' for sorting purposes.

This is solely used by the childrenSort method.

A higher score means the item will be lower in the list. To avoid score collisions, each "score category" has a reasonable space to accomodate elements. The $key is added to the $score to preserve the original relative order of elements.

Parameters
int$key
array$array
Returns
int

Reimplemented from Sabre\VObject\Node.

Definition at line 284 of file Component.php.

284 {
285
286 $str = "BEGIN:" . $this->name . "\r\n";
287
303 $sortScore = function($key, $array) {
304
305 if ($array[$key] instanceof Component) {
306
307 // We want to encode VTIMEZONE first, this is a personal
308 // preference.
309 if ($array[$key]->name === 'VTIMEZONE') {
310 $score = 300000000;
311 return $score + $key;
312 } else {
313 $score = 400000000;
314 return $score + $key;
315 }
316 } else {
317 // Properties get encoded first
318 // VCARD version 4.0 wants the VERSION property to appear first
319 if ($array[$key] instanceof Property) {
320 if ($array[$key]->name === 'VERSION') {
321 $score = 100000000;
322 return $score + $key;
323 } else {
324 // All other properties
325 $score = 200000000;
326 return $score + $key;
327 }
328 }
329 }
330
331 };
332
333 $children = $this->children();
334 $tmp = $children;
335 uksort(
336 $children,
337 function($a, $b) use ($sortScore, $tmp) {
338
339 $sA = $sortScore($a, $tmp);
340 $sB = $sortScore($b, $tmp);
341
342 return $sA - $sB;
343
344 }
345 );
346
347 foreach ($children as $child) $str .= $child->serialize();
348 $str .= "END:" . $this->name . "\r\n";
349
350 return $str;
351
352 }

References Sabre\VObject\Component\$children, $key, and Sabre\VObject\Component\children().

Referenced by Sabre\VObject\Cli\repair(), and Sabre\VObject\Writer\write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate()

Sabre\VObject\Component::validate (   $options = 0)

Validates the node for correctness.

The following options are supported: Node::REPAIR - May attempt to automatically repair the problem. Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.

This method returns an array with detected problems. Every element has the following properties:

  • level - problem level.
  • message - A human-readable string describing the issue.
  • node - A reference to the problematic node.

The level means: 1 - The issue was repaired (only happens if REPAIR was turned on). 2 - A warning. 3 - An error.

Parameters
int$options
Returns
array

Reimplemented from Sabre\VObject\Node.

Reimplemented in Sabre\VObject\Component\Available, Sabre\VObject\Component\VAvailability, Sabre\VObject\Component\VCalendar, Sabre\VObject\Component\VCard, and Sabre\VObject\Component\VTodo.

Definition at line 607 of file Component.php.

607 {
608
609 $rules = $this->getValidationRules();
610 $defaults = $this->getDefaults();
611
612 $propertyCounters = [];
613
614 $messages = [];
615
616 foreach ($this->children() as $child) {
617 $name = strtoupper($child->name);
618 if (!isset($propertyCounters[$name])) {
619 $propertyCounters[$name] = 1;
620 } else {
621 $propertyCounters[$name]++;
622 }
623 $messages = array_merge($messages, $child->validate($options));
624 }
625
626 foreach ($rules as $propName => $rule) {
627
628 switch ($rule) {
629 case '0' :
630 if (isset($propertyCounters[$propName])) {
631 $messages[] = [
632 'level' => 3,
633 'message' => $propName . ' MUST NOT appear in a ' . $this->name . ' component',
634 'node' => $this,
635 ];
636 }
637 break;
638 case '1' :
639 if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] !== 1) {
640 $repaired = false;
641 if ($options & self::REPAIR && isset($defaults[$propName])) {
642 $this->add($propName, $defaults[$propName]);
643 $repaired = true;
644 }
645 $messages[] = [
646 'level' => $repaired ? 1 : 3,
647 'message' => $propName . ' MUST appear exactly once in a ' . $this->name . ' component',
648 'node' => $this,
649 ];
650 }
651 break;
652 case '+' :
653 if (!isset($propertyCounters[$propName]) || $propertyCounters[$propName] < 1) {
654 $messages[] = [
655 'level' => 3,
656 'message' => $propName . ' MUST appear at least once in a ' . $this->name . ' component',
657 'node' => $this,
658 ];
659 }
660 break;
661 case '*' :
662 break;
663 case '?' :
664 if (isset($propertyCounters[$propName]) && $propertyCounters[$propName] > 1) {
665 $level = 3;
666
667 // We try to repair the same property appearing multiple times with the exact same value
668 // by removing the duplicates and keeping only one property
669 if ($options & self::REPAIR) {
670 $properties = array_unique($this->select($propName), SORT_REGULAR);
671
672 if (count($properties) === 1) {
673 $this->remove($propName);
674 $this->add($properties[0]);
675
676 $level = 1;
677 }
678 }
679
680 $messages[] = [
681 'level' => $level,
682 'message' => $propName . ' MUST NOT appear more than once in a ' . $this->name . ' component',
683 'node' => $this,
684 ];
685 }
686 break;
687
688 }
689
690 }
691 return $messages;
692
693 }
$messages
Definition: en.php:5
$rule
Definition: showstats.php:43

References $messages, Sabre\VObject\Component\$name, PHPMailer\PHPMailer\$options, $rule, Sabre\VObject\Component\add(), Sabre\VObject\Component\children(), Sabre\VObject\Node\count(), Sabre\VObject\Component\getDefaults(), Sabre\VObject\Component\getValidationRules(), and Sabre\VObject\Component\select().

Referenced by Sabre\VObject\Cli\repair(), and Sabre\VObject\Cli\validate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ xmlSerialize()

Sabre\VObject\Component::xmlSerialize ( Xml\Writer  $writer)

This method serializes the data into XML.

This is used to create xCard or xCal documents.

Parameters
Xml\Writer$writerXML writer.
Returns
void

Reimplemented from Sabre\VObject\Node.

Reimplemented in Sabre\VObject\Component\VCard.

Definition at line 391 of file Component.php.

391 {
392
393 $components = [];
394 $properties = [];
395
396 foreach ($this->children as $childGroup) {
397 foreach ($childGroup as $child) {
398 if ($child instanceof self) {
399 $components[] = $child;
400 } else {
401 $properties[] = $child;
402 }
403 }
404 }
405
406 $writer->startElement(strtolower($this->name));
407
408 if (!empty($properties)) {
409
410 $writer->startElement('properties');
411
412 foreach ($properties as $property) {
413 $property->xmlSerialize($writer);
414 }
415
416 $writer->endElement();
417
418 }
419
420 if (!empty($components)) {
421
422 $writer->startElement('components');
423
424 foreach ($components as $component) {
425 $component->xmlSerialize($writer);
426 }
427
428 $writer->endElement();
429 }
430
431 $writer->endElement();
432
433 }

References Sabre\VObject\Component\children().

Referenced by Sabre\VObject\Writer\writeXml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $children

Sabre\VObject\Component::$children = []
protected

◆ $name


The documentation for this class was generated from the following file: