/** * Sets the json value, as it would appear in a jCard or jCal object. * * The value must always be an array. * * @param array $value * @return void */ public function setJsonValue(array $value) { $value = array_map(function ($item) { return strtr(implode('/', $item), array(':' => '', '-' => '')); }, $value); parent::setJsonValue($value); }
/** * Validates the node for correctness. * * The following options are supported: * - Node::REPAIR - If something is broken, and automatic repair may * be attempted. * * An array is returned with warnings. * * Every item in the array has the following properties: * * level - (number between 1 and 3 with severity information) * * message - (human readable message) * * node - (reference to the offending node) * * @param int $options * @return array */ public function validate($options = 0) { $warnings = parent::validate($options); if (isset($this->minimumPropertyValues[$this->name])) { $minimum = $this->minimumPropertyValues[$this->name]; $parts = $this->getParts(); if (count($parts) < $minimum) { $warnings[] = array('level' => 1, 'message' => 'This property must have at least ' . $minimum . ' components. It only has ' . count($parts), 'node' => $this); if ($options & self::REPAIR) { $parts = array_pad($parts, $minimum, ''); $this->setParts($parts); } } } return $warnings; }
/** * We need to intercept offsetSet, because it may be used to alter the * VALUE from DATE-TIME to DATE or vice-versa. * * @param string $name * @param mixed $value * @return void */ public function offsetSet($name, $value) { parent::offsetSet($name, $value); if (strtoupper($name) !== 'VALUE') { return; } // This will ensure that dates are correctly encoded. $this->setDateTimes($this->getDateTimes()); }
/** * Colorizes a property. * * @param Property $property * @return void */ protected function serializeProperty(Property $property) { if ($property->group) { $this->cWrite('default', $property->group); $this->cWrite('red', '.'); } $str = ''; $this->cWrite('yellow', $property->name); foreach ($property->parameters as $param) { $this->cWrite('red', ';'); $this->cWrite('blue', $param->serialize()); } $this->cWrite('red', ':'); if ($property instanceof Property\Binary) { $this->cWrite('default', 'embedded binary stripped. (' . strlen($property->getValue()) . ' bytes)'); } else { $parts = $property->getParts(); $first1 = true; // Looping through property values foreach ($parts as $part) { if ($first1) { $first1 = false; } else { $this->cWrite('red', $property->delimiter); } $first2 = true; // Looping through property sub-values foreach ((array) $part as $subPart) { if ($first2) { $first2 = false; } else { // The sub-value delimiter is always comma $this->cWrite('red', ','); } $subPart = strtr($subPart, array('\\' => $this->colorize('purple', '\\\\', 'green'), ';' => $this->colorize('purple', '\\;', 'green'), ',' => $this->colorize('purple', '\\,', 'green'), "\n" => $this->colorize('purple', "\\n\n\t", 'green'), "\r" => "")); $this->cWrite('green', $subPart); } } } $this->cWrite("default", "\n"); }
/** * Sets the json value, as it would appear in a jCard or jCal object. * * The value must always be an array. * * @param array $value * @return void */ public function setJsonValue(array $value) { $value = array_map('base64_decode', $value); parent::setJsonValue($value); }