public function convert(Component\VCard $input, $targetVersion)
    {
        $inputVersion = $input->getDocumentType();
        if ($inputVersion === $targetVersion) {
            return clone $input;
        }

        if (!in_array($inputVersion, [Document::VCARD21, Document::VCARD30, Document::VCARD40])) {
            throw new \InvalidArgumentException('Only vCard 2.1, 3.0 and 4.0 are supported for the input data');
        }
        if (!in_array($targetVersion, [Document::VCARD30, Document::VCARD40])) {
            throw new \InvalidArgumentException('You can only use vCard 3.0 or 4.0 for the target version');
        }

        $newVersion = Document::VCARD40 === $targetVersion ? '4.0' : '3.0';

        $output = new Component\VCard([
            'VERSION' => $newVersion,
        ]);

        // We might have generated a default UID. Remove it!
        unset($output->UID);

        foreach ($input->children() as $property) {
            $this->convertProperty($input, $output, $property, $targetVersion);
        }

        return $output;
    }
public function convert(Component\VCard $input, $targetVersion)
    {
        $inputVersion = $input->getDocumentType();
        if ($inputVersion === $targetVersion) {
            return clone $input;
        }

        if (!in_array($inputVersion, [Document::VCARD21, Document::VCARD30, Document::VCARD40])) {
            throw new \InvalidArgumentException('Only vCard 2.1, 3.0 and 4.0 are supported for the input data');
        }
        if (!in_array($targetVersion, [Document::VCARD30, Document::VCARD40])) {
            throw new \InvalidArgumentException('You can only use vCard 3.0 or 4.0 for the target version');
        }

        $newVersion = Document::VCARD40 === $targetVersion ? '4.0' : '3.0';

        $output = new Component\VCard([
            'VERSION' => $newVersion,
        ]);

        // We might have generated a default UID. Remove it!
        unset($output->UID);

        foreach ($input->children() as $property) {
            $this->convertProperty($input, $output, $property, $targetVersion);
        }

        return $output;
    }
public function convert ( Component \ VCard $ input , $ targetVersion ) { $ inputVersion = $ input -> getDocumentType ( ) ; if ( $ inputVersion === $ targetVersion ) { return clone $ input ; } if ( ! in_array ( $ inputVersion , [ Document :: VCARD21 , Document :: VCARD30 , Document :: VCARD40 ] ) ) { throw new \ InvalidArgumentException ( 'Only vCard 2.1, 3.0 and 4.0 are supported for the input data' ) ; } if ( ! in_array ( $ targetVersion , [ Document :: VCARD30 , Document :: VCARD40 ] ) ) { throw new \ InvalidArgumentException ( 'You can only use vCard 3.0 or 4.0 for the target version' ) ; } $ newVersion = Document :: VCARD40 === $ targetVersion ? '4.0' : '3.0' ; $ output = new Component \ VCard ( [ 'VERSION' => $ newVersion , ] ) ; // We might have generated a default UID. Remove it! unset ( $ output -> UID ) ; foreach ( $ input -> children ( ) as $ property ) { $ this -> convertProperty ( $ input , $ output , $ property , $ targetVersion ) ; } return $ output ; }
Converts a vCard object to a new version.

targetVersion must be one of:
Document::VCARD21
Document::VCARD30
Document::VCARD40

Currently only 3.0 and 4.0 as input and output versions.

2.1 has some minor support for the input version, it's incomplete at the
moment though.

If input and output version are identical, a clone is returned.

@param Component\VCard $input
@param int             $targetVersion
Converts a vCard object to a new version .