Skip to content

Commit 17e6eea

Browse files
hanzistaabm
authored andcommitted
Add PHONE-NUMBER value type (used for TEL in vCard 3.0) (#486)
Signed-off-by: Christian Kraus <[email protected]>
1 parent 82d2d6a commit 17e6eea

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

lib/Component/VCard.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class VCard extends VObject\Document
5757
'FLOAT' => 'Sabre\\VObject\\Property\\FloatValue',
5858
'INTEGER' => 'Sabre\\VObject\\Property\\IntegerValue',
5959
'LANGUAGE-TAG' => 'Sabre\\VObject\\Property\\VCard\\LanguageTag',
60+
'PHONE-NUMBER' => 'Sabre\\VObject\\Property\\VCard\\PhoneNumber', // vCard 3.0 only
6061
'TIMESTAMP' => 'Sabre\\VObject\\Property\\VCard\\TimeStamp',
6162
'TEXT' => 'Sabre\\VObject\\Property\\Text',
6263
'TIME' => 'Sabre\\VObject\\Property\\Time',

lib/Property/VCard/PhoneNumber.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Sabre\VObject\Property\VCard;
4+
5+
use Sabre\VObject\Property;
6+
7+
/**
8+
* PhoneNumber property.
9+
*
10+
* This object encodes PHONE-NUMBER values.
11+
*
12+
* @author Christian Kraus <[email protected]>
13+
*/
14+
class PhoneNumber extends Property\Text
15+
{
16+
protected $structuredValues = [];
17+
18+
/**
19+
* Returns the type of value.
20+
*
21+
* This corresponds to the VALUE= parameter. Every property also has a
22+
* 'default' valueType.
23+
*
24+
* @return string
25+
*/
26+
public function getValueType()
27+
{
28+
return 'PHONE-NUMBER';
29+
}
30+
}

lib/VCardConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp
8383
if (!$valueType) {
8484
$valueType = $property->getValueType();
8585
}
86+
if (Document::VCARD30 !== $targetVersion && 'PHONE-NUMBER' === $valueType) {
87+
$valueType = null;
88+
}
8689
$newProperty = $output->createProperty(
8790
$property->name,
8891
$property->getParts(),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Sabre\VObject\Property\VCard;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Sabre\VObject;
7+
8+
class PhoneNumberTest extends TestCase
9+
{
10+
public function testParser()
11+
{
12+
$input = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=HOME;VALUE=PHONE-NUMBER:+1234\r\nEND:VCARD\r\n";
13+
14+
$vCard = VObject\Reader::read($input);
15+
$this->assertInstanceOf('Sabre\VObject\Property\VCard\PhoneNumber', $vCard->TEL);
16+
$this->assertEquals('PHONE-NUMBER', $vCard->TEL->getValueType());
17+
$this->assertEquals($input, $vCard->serialize());
18+
}
19+
}

tests/VObject/VCardConverterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,4 +518,34 @@ public function testNoLabel()
518518

519519
$this->assertEquals($expected, str_replace("\r", '', $vcard));
520520
}
521+
522+
public function testPhoneNumberValueTypeGetsRemoved()
523+
{
524+
$input = <<<VCF
525+
BEGIN:VCARD
526+
VERSION:3.0
527+
UID:foo
528+
FN:John Doe
529+
TEL;TYPE=HOME;VALUE=PHONE-NUMBER:+1234
530+
END:VCARD
531+
532+
VCF;
533+
534+
$output = <<<VCF
535+
BEGIN:VCARD
536+
VERSION:4.0
537+
UID:foo
538+
FN:John Doe
539+
TEL;TYPE=HOME:+1234
540+
END:VCARD
541+
VCF;
542+
543+
$vcard = Reader::read($input);
544+
$vcard = $vcard->convert(Document::VCARD40);
545+
546+
$this->assertVObjectEqualsVObject(
547+
$output,
548+
$vcard
549+
);
550+
}
521551
}

0 commit comments

Comments
 (0)