diff options
Diffstat (limited to 'vendor/sabre/vobject/lib/Parameter.php')
-rw-r--r-- | vendor/sabre/vobject/lib/Parameter.php | 233 |
1 files changed, 106 insertions, 127 deletions
diff --git a/vendor/sabre/vobject/lib/Parameter.php b/vendor/sabre/vobject/lib/Parameter.php index a99a33eec..2c9a8e7fd 100644 --- a/vendor/sabre/vobject/lib/Parameter.php +++ b/vendor/sabre/vobject/lib/Parameter.php @@ -17,8 +17,8 @@ use Sabre\Xml; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class Parameter extends Node { - +class Parameter extends Node +{ /** * Parameter name. * @@ -29,7 +29,7 @@ class Parameter extends Node { /** * vCard 2.1 allows parameters to be encoded without a name. * - * We can deduce the parameter name based on it's value. + * We can deduce the parameter name based on its value. * * @var bool */ @@ -50,8 +50,8 @@ class Parameter extends Node { * @param string $name * @param string $value */ - function __construct(Document $root, $name, $value = null) { - + public function __construct(Document $root, $name, $value = null) + { $this->name = strtoupper($name); $this->root = $root; if (is_null($name)) { @@ -62,13 +62,12 @@ class Parameter extends Node { // If guessParameterNameByValue() returns an empty string // above, we're actually dealing with a parameter that has no value. // In that case we have to move the value to the name. - if ($this->name === '') { + if ('' === $this->name) { $this->noName = false; $this->name = strtoupper($value); } else { $this->setValue($value); } - } /** @@ -82,85 +81,85 @@ class Parameter extends Node { * * @return string */ - static function guessParameterNameByValue($value) { + public static function guessParameterNameByValue($value) + { switch (strtoupper($value)) { - // Encodings - case '7-BIT' : - case 'QUOTED-PRINTABLE' : - case 'BASE64' : + case '7-BIT': + case 'QUOTED-PRINTABLE': + case 'BASE64': $name = 'ENCODING'; break; // Common types - case 'WORK' : - case 'HOME' : - case 'PREF' : + case 'WORK': + case 'HOME': + case 'PREF': // Delivery Label Type - case 'DOM' : - case 'INTL' : - case 'POSTAL' : - case 'PARCEL' : + case 'DOM': + case 'INTL': + case 'POSTAL': + case 'PARCEL': // Telephone types - case 'VOICE' : - case 'FAX' : - case 'MSG' : - case 'CELL' : - case 'PAGER' : - case 'BBS' : - case 'MODEM' : - case 'CAR' : - case 'ISDN' : - case 'VIDEO' : + case 'VOICE': + case 'FAX': + case 'MSG': + case 'CELL': + case 'PAGER': + case 'BBS': + case 'MODEM': + case 'CAR': + case 'ISDN': + case 'VIDEO': // EMAIL types (lol) - case 'AOL' : - case 'APPLELINK' : - case 'ATTMAIL' : - case 'CIS' : - case 'EWORLD' : - case 'INTERNET' : - case 'IBMMAIL' : - case 'MCIMAIL' : - case 'POWERSHARE' : - case 'PRODIGY' : - case 'TLX' : - case 'X400' : + case 'AOL': + case 'APPLELINK': + case 'ATTMAIL': + case 'CIS': + case 'EWORLD': + case 'INTERNET': + case 'IBMMAIL': + case 'MCIMAIL': + case 'POWERSHARE': + case 'PRODIGY': + case 'TLX': + case 'X400': // Photo / Logo format types - case 'GIF' : - case 'CGM' : - case 'WMF' : - case 'BMP' : - case 'DIB' : - case 'PICT' : - case 'TIFF' : - case 'PDF' : - case 'PS' : - case 'JPEG' : - case 'MPEG' : - case 'MPEG2' : - case 'AVI' : - case 'QTIME' : + case 'GIF': + case 'CGM': + case 'WMF': + case 'BMP': + case 'DIB': + case 'PICT': + case 'TIFF': + case 'PDF': + case 'PS': + case 'JPEG': + case 'MPEG': + case 'MPEG2': + case 'AVI': + case 'QTIME': // Sound Digital Audio Type - case 'WAVE' : - case 'PCM' : - case 'AIFF' : + case 'WAVE': + case 'PCM': + case 'AIFF': // Key types - case 'X509' : - case 'PGP' : + case 'X509': + case 'PGP': $name = 'TYPE'; break; // Value types - case 'INLINE' : - case 'URL' : - case 'CONTENT-ID' : - case 'CID' : + case 'INLINE': + case 'URL': + case 'CONTENT-ID': + case 'CID': $name = 'VALUE'; break; @@ -177,13 +176,10 @@ class Parameter extends Node { * This may be either a single, or multiple strings in an array. * * @param string|array $value - * - * @return void */ - function setValue($value) { - + public function setValue($value) + { $this->value = $value; - } /** @@ -194,27 +190,23 @@ class Parameter extends Node { * * @return string|null */ - function getValue() { - + public function getValue() + { if (is_array($this->value)) { return implode(',', $this->value); } else { return $this->value; } - } /** * Sets multiple values for this parameter. * * @param array $value - * - * @return void */ - function setParts(array $value) { - + public function setParts(array $value) + { $this->value = $value; - } /** @@ -224,8 +216,8 @@ class Parameter extends Node { * * @return array */ - function getParts() { - + public function getParts() + { if (is_array($this->value)) { return $this->value; } elseif (is_null($this->value)) { @@ -233,7 +225,6 @@ class Parameter extends Node { } else { return [$this->value]; } - } /** @@ -243,17 +234,14 @@ class Parameter extends Node { * parameter value list. * * @param string|array $part - * - * @return void */ - function addValue($part) { - + public function addValue($part) + { if (is_null($this->value)) { $this->value = $part; } else { - $this->value = array_merge((array)$this->value, (array)$part); + $this->value = array_merge((array) $this->value, (array) $part); } - } /** @@ -267,13 +255,12 @@ class Parameter extends Node { * * @return bool */ - function has($value) { - + public function has($value) + { return in_array( strtolower($value), - array_map('strtolower', (array)$this->value) + array_map('strtolower', (array) $this->value) ); - } /** @@ -281,25 +268,24 @@ class Parameter extends Node { * * @return string */ - function serialize() { - + public function serialize() + { $value = $this->getParts(); - if (count($value) === 0) { - return $this->name . '='; + if (0 === count($value)) { + return $this->name.'='; } - if ($this->root->getDocumentType() === Document::VCARD21 && $this->noName) { - + if (Document::VCARD21 === $this->root->getDocumentType() && $this->noName) { return implode(';', $value); - } - return $this->name . '=' . array_reduce( + return $this->name.'='.array_reduce( $value, - function($out, $item) { - - if (!is_null($out)) $out .= ','; + function ($out, $item) { + if (!is_null($out)) { + $out .= ','; + } // If there's no special characters in the string, we'll use the simple // format. @@ -318,24 +304,23 @@ class Parameter extends Node { // severaly trips on + characters not being quoted, so we // added + as well. if (!preg_match('#(?: [\n":;\^,\+] )#x', $item)) { - return $out . $item; + return $out.$item; } else { // Enclosing in double-quotes, and using RFC6868 for encoding any // special characters - $out .= '"' . strtr( + $out .= '"'.strtr( $item, [ - '^' => '^^', + '^' => '^^', "\n" => '^n', - '"' => '^\'', + '"' => '^\'', ] - ) . '"'; + ).'"'; + return $out; } - } ); - } /** @@ -344,26 +329,22 @@ class Parameter extends Node { * * @return array */ - function jsonSerialize() { - + public function jsonSerialize() + { return $this->value; - } /** * This method serializes the data into XML. This is used to create xCard or * xCal documents. * - * @param Xml\Writer $writer XML writer. - * - * @return void + * @param Xml\Writer $writer XML writer */ - function xmlSerialize(Xml\Writer $writer) { - + public function xmlSerialize(Xml\Writer $writer) + { foreach (explode(',', $this->value) as $value) { $writer->writeElement('text', $value); } - } /** @@ -371,10 +352,9 @@ class Parameter extends Node { * * @return string */ - function __toString() { - - return (string)$this->getValue(); - + public function __toString() + { + return (string) $this->getValue(); } /** @@ -382,13 +362,12 @@ class Parameter extends Node { * * @return ElementList */ - function getIterator() { - - if (!is_null($this->iterator)) + public function getIterator() + { + if (!is_null($this->iterator)) { return $this->iterator; + } - return $this->iterator = new ArrayIterator((array)$this->value); - + return $this->iterator = new ArrayIterator((array) $this->value); } - } |