summaryrefslogtreecommitdiffstats
path: root/3rdparty/Sabre/VObject/Property.php
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/Sabre/VObject/Property.php')
-rwxr-xr-x[-rw-r--r--]3rdparty/Sabre/VObject/Property.php177
1 files changed, 118 insertions, 59 deletions
diff --git a/3rdparty/Sabre/VObject/Property.php b/3rdparty/Sabre/VObject/Property.php
index 06058229043..ce74fe3865b 100644..100755
--- a/3rdparty/Sabre/VObject/Property.php
+++ b/3rdparty/Sabre/VObject/Property.php
@@ -4,58 +4,103 @@
* VObject Property
*
* A property in VObject is usually in the form PARAMNAME:paramValue.
- * An example is : SUMMARY:Weekly meeting
+ * An example is : SUMMARY:Weekly meeting
*
* Properties can also have parameters:
* SUMMARY;LANG=en:Weekly meeting.
*
- * Parameters can be accessed using the ArrayAccess interface.
+ * Parameters can be accessed using the ArrayAccess interface.
*
* @package Sabre
* @subpackage VObject
- * @copyright Copyright (C) 2007-2011 Rooftop Solutions. All rights reserved.
- * @author Evert Pot (http://www.rooftopsolutions.nl/)
+ * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
+ * @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Property extends Sabre_VObject_Element {
/**
- * Propertyname
- *
- * @var string
+ * Propertyname
+ *
+ * @var string
*/
public $name;
/**
* Group name
- *
+ *
* This may be something like 'HOME' for vcards.
*
- * @var string
+ * @var string
*/
public $group;
/**
- * Property parameters
- *
- * @var array
+ * Property parameters
+ *
+ * @var array
*/
public $parameters = array();
/**
- * Property value
- *
- * @var string
+ * Property value
+ *
+ * @var string
*/
public $value;
/**
+ * If properties are added to this map, they will be automatically mapped
+ * to their respective classes, if parsed by the reader or constructed with
+ * the 'create' method.
+ *
+ * @var array
+ */
+ static public $classMap = array(
+ 'COMPLETED' => 'Sabre_VObject_Property_DateTime',
+ 'CREATED' => 'Sabre_VObject_Property_DateTime',
+ 'DTEND' => 'Sabre_VObject_Property_DateTime',
+ 'DTSTAMP' => 'Sabre_VObject_Property_DateTime',
+ 'DTSTART' => 'Sabre_VObject_Property_DateTime',
+ 'DUE' => 'Sabre_VObject_Property_DateTime',
+ 'EXDATE' => 'Sabre_VObject_Property_MultiDateTime',
+ 'LAST-MODIFIED' => 'Sabre_VObject_Property_DateTime',
+ 'RECURRENCE-ID' => 'Sabre_VObject_Property_DateTime',
+ 'TRIGGER' => 'Sabre_VObject_Property_DateTime',
+ );
+
+ /**
+ * Creates the new property by name, but in addition will also see if
+ * there's a class mapped to the property name.
+ *
+ * @param string $name
+ * @param string $value
+ * @return void
+ */
+ static public function create($name, $value = null) {
+
+ $name = strtoupper($name);
+ $shortName = $name;
+ $group = null;
+ if (strpos($shortName,'.')!==false) {
+ list($group, $shortName) = explode('.', $shortName);
+ }
+
+ if (isset(self::$classMap[$shortName])) {
+ return new self::$classMap[$shortName]($name, $value);
+ } else {
+ return new self($name, $value);
+ }
+
+ }
+
+ /**
* Creates a new property object
- *
- * By default this object will iterate over its own children, but this can
+ *
+ * By default this object will iterate over its own children, but this can
* be overridden with the iterator argument
- *
- * @param string $name
+ *
+ * @param string $name
* @param string $value
* @param Sabre_VObject_ElementList $iterator
*/
@@ -73,10 +118,12 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
+
+
/**
- * Updates the internal value
- *
- * @param string $value
+ * Updates the internal value
+ *
+ * @param string $value
* @return void
*/
public function setValue($value) {
@@ -86,9 +133,9 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
/**
- * Turns the object back into a serialized blob.
- *
- * @return string
+ * Turns the object back into a serialized blob.
+ *
+ * @return string
*/
public function serialize() {
@@ -97,7 +144,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
if (count($this->parameters)) {
foreach($this->parameters as $param) {
-
+
$str.=';' . $param->serialize();
}
@@ -115,8 +162,8 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
$out = '';
while(strlen($str)>0) {
if (strlen($str)>75) {
- $out.= substr($str,0,75) . "\r\n";
- $str = ' ' . substr($str,75);
+ $out.= mb_strcut($str,0,75,'utf-8') . "\r\n";
+ $str = ' ' . mb_strcut($str,75,strlen($str),'utf-8');
} else {
$out.=$str . "\r\n";
$str='';
@@ -136,11 +183,11 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
* add(Sabre_VObject_Parameter $element)
* add(string $name, $value)
*
- * The first version adds an Parameter
- * The second adds a property as a string.
- *
- * @param mixed $item
- * @param mixed $itemValue
+ * The first version adds an Parameter
+ * The second adds a property as a string.
+ *
+ * @param mixed $item
+ * @param mixed $itemValue
* @return void
*/
public function add($item, $itemValue = null) {
@@ -153,7 +200,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
$this->parameters[] = $item;
} elseif(is_string($item)) {
- if (!is_scalar($itemValue)) {
+ if (!is_scalar($itemValue) && !is_null($itemValue)) {
throw new InvalidArgumentException('The second argument must be scalar');
}
$parameter = new Sabre_VObject_Parameter($item,$itemValue);
@@ -161,21 +208,20 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
$this->parameters[] = $parameter;
} else {
-
+
throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
}
}
-
/* ArrayAccess interface {{{ */
/**
* Checks if an array element exists
- *
- * @param mixed $name
- * @return bool
+ *
+ * @param mixed $name
+ * @return bool
*/
public function offsetExists($name) {
@@ -191,16 +237,16 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
/**
- * Returns a parameter, or parameter list.
- *
- * @param string $name
- * @return Sabre_VObject_Element
+ * Returns a parameter, or parameter list.
+ *
+ * @param string $name
+ * @return Sabre_VObject_Element
*/
public function offsetGet($name) {
if (is_int($name)) return parent::offsetGet($name);
$name = strtoupper($name);
-
+
$result = array();
foreach($this->parameters as $parameter) {
if ($parameter->name == $name)
@@ -219,8 +265,8 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
/**
- * Creates a new parameter
- *
+ * Creates a new parameter
+ *
* @param string $name
* @param mixed $value
* @return void
@@ -230,7 +276,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
if (is_int($name)) return parent::offsetSet($name, $value);
if (is_scalar($value)) {
- if (!is_string($name))
+ if (!is_string($name))
throw new InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
$this->offsetUnset($name);
@@ -242,7 +288,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
if (!is_null($name))
throw new InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a Sabre_VObject_Parameter. Add using $array[]=$parameterObject.');
- $value->parent = $this;
+ $value->parent = $this;
$this->parameters[] = $value;
} else {
throw new InvalidArgumentException('You can only add parameters to the property object');
@@ -251,17 +297,16 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
/**
- * Removes one or more parameters with the specified name
- *
- * @param string $name
- * @return void
+ * Removes one or more parameters with the specified name
+ *
+ * @param string $name
+ * @return void
*/
public function offsetUnset($name) {
- if (is_int($name)) return parent::offsetUnset($name, $value);
+ if (is_int($name)) return parent::offsetUnset($name);
$name = strtoupper($name);
-
- $result = array();
+
foreach($this->parameters as $key=>$parameter) {
if ($parameter->name == $name) {
$parameter->parent = null;
@@ -275,15 +320,29 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
/* }}} */
/**
- * Called when this object is being cast to a string
- *
- * @return string
+ * Called when this object is being cast to a string
+ *
+ * @return string
*/
public function __toString() {
- return $this->value;
+ return (string)$this->value;
}
+ /**
+ * This method is automatically called when the object is cloned.
+ * Specifically, this will ensure all child elements are also cloned.
+ *
+ * @return void
+ */
+ public function __clone() {
+
+ foreach($this->parameters as $key=>$child) {
+ $this->parameters[$key] = clone $child;
+ $this->parameters[$key]->parent = $this;
+ }
+
+ }
}