ICal\ICal::addCalendarComponentWithKeyAndValue PHP Method

addCalendarComponentWithKeyAndValue() protected method

Add to $this->ical array one value and key.
protected addCalendarComponentWithKeyAndValue ( string $component, string | boolean $keyword, string $value ) : void
$component string This could be VTODO, VEVENT, VCALENDAR, ...
$keyword string | boolean The keyword, for example DTSTART
$value string The value, for example 20110105T090000Z
return void
    protected function addCalendarComponentWithKeyAndValue($component, $keyword, $value)
    {
        if ($keyword == false) {
            $keyword = $this->lastKeyword;
        }
        switch ($component) {
            case 'VTODO':
                $this->cal[$component][$this->todoCount - 1][$keyword] = $value;
                break;
            case 'VEVENT':
                if (!isset($this->cal[$component][$this->eventCount - 1][$keyword . '_array'])) {
                    $this->cal[$component][$this->eventCount - 1][$keyword . '_array'] = array();
                }
                if (is_array($value)) {
                    // Add array of properties to the end
                    array_push($this->cal[$component][$this->eventCount - 1][$keyword . '_array'], $value);
                } else {
                    if (!isset($this->cal[$component][$this->eventCount - 1][$keyword])) {
                        $this->cal[$component][$this->eventCount - 1][$keyword] = $value;
                    }
                    if ($keyword === 'EXDATE') {
                        if (trim($value) === $value) {
                            $this->cal[$component][$this->eventCount - 1][$keyword . '_array'][] = explode(',', $value);
                        } else {
                            $value = explode(',', implode(',', $this->cal[$component][$this->eventCount - 1][$keyword . '_array'][1]) . trim($value));
                            $this->cal[$component][$this->eventCount - 1][$keyword . '_array'][1] = $value;
                        }
                    } else {
                        $this->cal[$component][$this->eventCount - 1][$keyword . '_array'][] = $value;
                        if ($keyword === 'DURATION') {
                            $duration = new \DateInterval($value);
                            array_push($this->cal[$component][$this->eventCount - 1][$keyword . '_array'], $duration);
                        }
                    }
                    // Glue back together for multi-line content
                    if ($this->cal[$component][$this->eventCount - 1][$keyword] != $value) {
                        $ord = isset($value[0]) ? ord($value[0]) : null;
                        // First char
                        if (in_array($ord, array(9, 32))) {
                            // Is space or tab?
                            $value = substr($value, 1);
                            // Only trim the first character
                        }
                        // Account for multiple definitions of current keyword (e.g. ATTENDEE)
                        if (is_array($this->cal[$component][$this->eventCount - 1][$keyword . '_array'][1])) {
                            if ($keyword === 'EXDATE') {
                                // This will give out a comma separated EXDATE string as per RFC2445
                                // Example: EXDATE:19960402T010000Z,19960403T010000Z,19960404T010000Z
                                // Usage: $event['EXDATE'] will print out 19960402T010000Z,19960403T010000Z,19960404T010000Z
                                $value = is_array($value) ? implode(',', $value) : $value;
                                $this->cal[$component][$this->eventCount - 1][$keyword] = $value;
                            } else {
                                // Concat value *with separator* as content spans multiple lines
                                $this->cal[$component][$this->eventCount - 1][$keyword] .= ';' . $value;
                            }
                        } else {
                            // Concat value as content spans multiple lines
                            $this->cal[$component][$this->eventCount - 1][$keyword] .= $value;
                        }
                    }
                }
                break;
            case 'VFREEBUSY':
                $this->cal[$component][$this->freebusyCount - 1][$keyword] = $value;
                break;
            default:
                $this->cal[$component][$keyword] = $value;
                break;
        }
        $this->lastKeyword = $keyword;
    }