protected function convert($vObj)
    {
        $json = false;
        $convertVersion = null;
        $forceInput = null;

        switch ($this->format) {
            case 'json':
                $json = true;
                if ('VCARD' === $vObj->name) {
                    $convertVersion = Document::VCARD40;
                }
                break;
            case 'jcard':
                $json = true;
                $forceInput = 'VCARD';
                $convertVersion = Document::VCARD40;
                break;
            case 'jcal':
                $json = true;
                $forceInput = 'VCALENDAR';
                break;
            case 'mimedir':
            case 'icalendar':
            case 'icalendar20':
            case 'vcard':
                break;
            case 'vcard21':
                $convertVersion = Document::VCARD21;
                break;
            case 'vcard30':
                $convertVersion = Document::VCARD30;
                break;
            case 'vcard40':
                $convertVersion = Document::VCARD40;
                break;
        }

        if ($forceInput && $vObj->name !== $forceInput) {
            throw new \Exception('You cannot convert a '.strtolower($vObj->name).' to '.$this->format);
        }
        if ($convertVersion) {
            $vObj = $vObj->convert($convertVersion);
        }
        if ($json) {
            $jsonOptions = 0;
            if ($this->pretty) {
                $jsonOptions = JSON_PRETTY_PRINT;
            }
            fwrite($this->stdout, json_encode($vObj->jsonSerialize(), $jsonOptions));
        } else {
            fwrite($this->stdout, $vObj->serialize());
        }

        return 0;
    }
protected function convert($vObj)
    {
        $json = false;
        $convertVersion = null;
        $forceInput = null;

        switch ($this->format) {
            case 'json':
                $json = true;
                if ('VCARD' === $vObj->name) {
                    $convertVersion = Document::VCARD40;
                }
                break;
            case 'jcard':
                $json = true;
                $forceInput = 'VCARD';
                $convertVersion = Document::VCARD40;
                break;
            case 'jcal':
                $json = true;
                $forceInput = 'VCALENDAR';
                break;
            case 'mimedir':
            case 'icalendar':
            case 'icalendar20':
            case 'vcard':
                break;
            case 'vcard21':
                $convertVersion = Document::VCARD21;
                break;
            case 'vcard30':
                $convertVersion = Document::VCARD30;
                break;
            case 'vcard40':
                $convertVersion = Document::VCARD40;
                break;
        }

        if ($forceInput && $vObj->name !== $forceInput) {
            throw new \Exception('You cannot convert a '.strtolower($vObj->name).' to '.$this->format);
        }
        if ($convertVersion) {
            $vObj = $vObj->convert($convertVersion);
        }
        if ($json) {
            $jsonOptions = 0;
            if ($this->pretty) {
                $jsonOptions = JSON_PRETTY_PRINT;
            }
            fwrite($this->stdout, json_encode($vObj->jsonSerialize(), $jsonOptions));
        } else {
            fwrite($this->stdout, $vObj->serialize());
        }

        return 0;
    }
protected function convert ( $ vObj ) { $ json = false ; $ convertVersion = null ; $ forceInput = null ; switch ( $ this -> format ) { case 'json' : $ json = true ; if ( 'VCARD' === $ vObj -> name ) { $ convertVersion = Document :: VCARD40 ; } break ; case 'jcard' : $ json = true ; $ forceInput = 'VCARD' ; $ convertVersion = Document :: VCARD40 ; break ; case 'jcal' : $ json = true ; $ forceInput = 'VCALENDAR' ; break ; case 'mimedir' : case 'icalendar' : case 'icalendar20' : case 'vcard' : break ; case 'vcard21' : $ convertVersion = Document :: VCARD21 ; break ; case 'vcard30' : $ convertVersion = Document :: VCARD30 ; break ; case 'vcard40' : $ convertVersion = Document :: VCARD40 ; break ; } if ( $ forceInput && $ vObj -> name !== $ forceInput ) { throw new \ Exception ( 'You cannot convert a ' . strtolower ( $ vObj -> name ) . ' to ' . $ this -> format ) ; } if ( $ convertVersion ) { $ vObj = $ vObj -> convert ( $ convertVersion ) ; } if ( $ json ) { $ jsonOptions = 0 ; if ( $ this -> pretty ) { $ jsonOptions = JSON_PRETTY_PRINT ; } fwrite ( $ this -> stdout , json_encode ( $ vObj -> jsonSerialize ( ) , $ jsonOptions ) ) ; } else { fwrite ( $ this -> stdout , $ vObj -> serialize ( ) ) ; } return 0 ; }
Converts a vObject file to a new format.

@param Component $vObj

@return int
Converts a vObject file to a new format .