123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- <?php
- namespace Sabre\VObject;
- use
- ArrayObject;
- class Parameter extends Node {
-
- public $name;
-
- public $noName = false;
-
- protected $value;
-
- public function __construct(Document $root, $name, $value = null) {
- $this->name = strtoupper($name);
- $this->root = $root;
- if (is_null($name)) {
- $this->noName = true;
- $this->name = static::guessParameterNameByValue($value);
- }
-
-
-
- if ($this->name === '') {
- $this->noName = false;
- $this->name = strtoupper($value);
- } else {
- $this->setValue($value);
- }
- }
-
- public static function guessParameterNameByValue($value) {
- switch(strtoupper($value)) {
-
- case '7-BIT' :
- case 'QUOTED-PRINTABLE' :
- case 'BASE64' :
- $name = 'ENCODING';
- break;
-
- case 'WORK' :
- case 'HOME' :
- case 'PREF' :
-
- case 'DOM' :
- case 'INTL' :
- case 'POSTAL' :
- case 'PARCEL' :
-
- case 'VOICE' :
- case 'FAX' :
- case 'MSG' :
- case 'CELL' :
- case 'PAGER' :
- case 'BBS' :
- case 'MODEM' :
- case 'CAR' :
- case 'ISDN' :
- case 'VIDEO' :
-
- 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 '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 'WAVE' :
- case 'PCM' :
- case 'AIFF' :
-
- case 'X509' :
- case 'PGP' :
- $name = 'TYPE';
- break;
-
- case 'INLINE' :
- case 'URL' :
- case 'CONTENT-ID' :
- case 'CID' :
- $name = 'VALUE';
- break;
- default:
- $name = '';
- }
- return $name;
- }
-
- public function setValue($value) {
- $this->value = $value;
- }
-
- public function getValue() {
- if (is_array($this->value)) {
- return implode(',' , $this->value);
- } else {
- return $this->value;
- }
- }
-
- public function setParts(array $value) {
- $this->value = $value;
- }
-
- public function getParts() {
- if (is_array($this->value)) {
- return $this->value;
- } elseif (is_null($this->value)) {
- return array();
- } else {
- return array($this->value);
- }
- }
-
- public function addValue($part) {
- if (is_null($this->value)) {
- $this->value = $part;
- } else {
- $this->value = array_merge((array)$this->value, (array)$part);
- }
- }
-
- public function has($value) {
- return in_array(
- strtolower($value),
- array_map('strtolower', (array)$this->value)
- );
- }
-
- public function serialize() {
- $value = $this->getParts();
- if (count($value)===0) {
- return $this->name . '=';
- }
- if ($this->root->getDocumentType() === Document::VCARD21 && $this->noName) {
- return implode(';', $value);
- }
- return $this->name . '=' . array_reduce(
- $value,
- function($out, $item) {
- if (!is_null($out)) $out.=',';
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!preg_match('#(?: [\n":;\^,\+] )#x', $item)) {
- return $out.$item;
- } else {
-
-
- $out.='"' . strtr(
- $item,
- array(
- '^' => '^^',
- "\n" => '^n',
- '"' => '^\'',
- )
- ) . '"';
- return $out;
- }
- }
- );
- }
-
- public function jsonSerialize() {
- return $this->value;
- }
-
- public function __toString() {
- return (string)$this->getValue();
- }
-
- public function getIterator() {
- if (!is_null($this->iterator))
- return $this->iterator;
- return $this->iterator = new ArrayObject((array)$this->value);
- }
- }
|