Blame view
sources/3rdparty/sabre/vobject/lib/Sabre/VObject/Property/Compound.php
3.27 KB
|
03e52840d
|
1 2 3 4 5 6 7 |
<?php namespace Sabre\VObject\Property; use Sabre\VObject; /** |
|
6d9380f96
|
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
* Compound property. * * This class adds (de)serialization of compound properties to/from arrays. * * Currently the following properties from RFC 6350 are mapped to use this * class: * * N: Section 6.2.2 * ADR: Section 6.3.1 * ORG: Section 6.6.4 * CATEGORIES: Section 6.7.1 * * In order to use this correctly, you must call setParts and getParts to * retrieve and modify dates respectively. * * @author Thomas Tanghus (http://tanghus.net/) * @author Lars Kneschke * @author Evert Pot (http://evertpot.com/) * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/). * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ |
|
03e52840d
|
29 30 31 |
class Compound extends VObject\Property {
/**
|
|
6d9380f96
|
32 33 34 35 36 37 |
* If property names are added to this map, they will be (de)serialised as arrays
* using the getParts() and setParts() methods.
* The keys are the property names, values are delimiter chars.
*
* @var array
*/
|
|
03e52840d
|
38 |
static public $delimiterMap = array( |
|
6d9380f96
|
39 40 41 42 |
'N' => ';',
'ADR' => ';',
'ORG' => ';',
'CATEGORIES' => ',',
|
|
03e52840d
|
43 44 45 46 47 48 49 50 51 52 |
);
/**
* The currently used delimiter.
*
* @var string
*/
protected $delimiter = null;
/**
|
|
6d9380f96
|
53 54 55 56 57 |
* Get a compound value as an array.
*
* @param $name string
* @return array
*/
|
|
03e52840d
|
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 |
public function getParts() {
if (is_null($this->value)) {
return array();
}
$delimiter = $this->getDelimiter();
// split by any $delimiter which is NOT prefixed by a slash.
// Note that this is not a a perfect solution. If a value is prefixed
// by two slashes, it should actually be split anyway.
//
// Hopefully we can fix this better in a future version, where we can
// break compatibility a bit.
$compoundValues = preg_split("/(?<!\\\)$delimiter/", $this->value);
// remove slashes from any semicolon and comma left escaped in the single values
$compoundValues = array_map(
function($val) {
return strtr($val, array('\,' => ',', '\;' => ';'));
}, $compoundValues);
return $compoundValues;
}
/**
* Returns the delimiter for this property.
*
* @return string
*/
public function getDelimiter() {
if (!$this->delimiter) {
if (isset(self::$delimiterMap[$this->name])) {
$this->delimiter = self::$delimiterMap[$this->name];
} else {
// To be a bit future proof, we are going to default the
// delimiter to ;
$this->delimiter = ';';
}
}
return $this->delimiter;
}
/**
* Set a compound value as an array.
*
|
|
6d9380f96
|
107 108 109 110 |
*
* @param $name string
* @return array
*/
|
|
03e52840d
|
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
public function setParts(array $values) {
// add slashes to all semicolons and commas in the single values
$values = array_map(
function($val) {
return strtr($val, array(',' => '\,', ';' => '\;'));
}, $values);
$this->setValue(
implode($this->getDelimiter(), $values)
);
}
}
|