Skip to content

Commit f5ed2fb

Browse files
Merge PR from Jean-beru
1 parent c52a8c6 commit f5ed2fb

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ $vcard->addEmail('[email protected]');
4343
$vcard->addPhoneNumber(1234121212, 'PREF;WORK');
4444
$vcard->addPhoneNumber(123456789, 'WORK');
4545
$vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium');
46+
$vcard->addLabel('street, worktown, workpostcode Belgium');
4647
$vcard->addURL('http://www.jeroendesloovere.be');
4748

4849
$vcard->addPhoto(__DIR__ . '/landscape.jpeg');

src/VCard.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class VCard
4646
'email',
4747
'address',
4848
'phoneNumber',
49-
'url'
49+
'url',
50+
'label'
5051
];
5152

5253
/**
@@ -179,6 +180,25 @@ public function addJobtitle($jobtitle)
179180
return $this;
180181
}
181182

183+
/**
184+
* Add a label
185+
*
186+
* @param string $label
187+
* @param string $type
188+
*
189+
* @return $this
190+
*/
191+
public function addLabel($label, $type = '')
192+
{
193+
$this->setProperty(
194+
'label',
195+
'LABEL' . ($type !== '' ? ';' . $type : ''),
196+
$label
197+
);
198+
199+
return $this;
200+
}
201+
182202
/**
183203
* Add role
184204
*

tests/VCardTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,18 @@ public function testSpecialFirstNameAndLastName2()
427427
$this->assertEquals('garcon-jeroen', $this->vcard->getFilename());
428428
}
429429

430+
/**
431+
* Test multiple labels
432+
*/
433+
public function testMultipleLabels()
434+
{
435+
$this->assertSame($this->vcard, $this->vcard->addLabel('My label'));
436+
$this->assertSame($this->vcard, $this->vcard->addLabel('My work label', 'WORK'));
437+
$this->assertSame(2, count($this->vcard->getProperties()));
438+
$this->assertContains('LABEL:My label', $this->vcard->getOutput());
439+
$this->assertContains('LABEL;WORK:My work label', $this->vcard->getOutput());
440+
}
441+
430442
public function testChunkSplitUnicode()
431443
{
432444
$class_handler = new \ReflectionClass('JeroenDesloovere\VCard\VCard');

0 commit comments

Comments
 (0)