Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of an attribute list like "PREF;WORK;FAX", the OSX contacts a… #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function addAddress(
) {
// init value
$value = $name . ';' . $extended . ';' . $street . ';' . $city . ';' . $region . ';' . $zip . ';' . $country;

$type = $this->transformTypes($type);
// set property
$this->setProperty(
'address',
Expand Down Expand Up @@ -154,9 +154,10 @@ public function addCompany($company, $department = '')
*/
public function addEmail($address, $type = '')
{
$type = $this->transformTypes($type);
$this->setProperty(
'email',
'EMAIL;INTERNET' . (($type != '') ? ';' . $type : ''),
'EMAIL;type=INTERNET' . (($type != '') ? ';' . $type : ''),
$address
);

Expand Down Expand Up @@ -404,6 +405,7 @@ public function addCategories($categories)
*/
public function addPhoneNumber($number, $type = '')
{
$type = $this->transformTypes($type);
$this->setProperty(
'phoneNumber',
'TEL' . (($type != '') ? ';' . $type : ''),
Expand Down Expand Up @@ -494,6 +496,7 @@ public function addPhotoContent($content)
*/
public function addURL($url, $type = '')
{
$type = $this->transformTypes($type);
$this->setProperty(
'url',
'URL' . (($type != '') ? ';' . $type : ''),
Expand Down Expand Up @@ -959,4 +962,24 @@ protected function shouldAttachmentBeCal()

return ($version < 8);
}

/**
* Takes type(s) string like "PREF;WORK;FAX" and adds "type=" to each type property.
*
* @param string $types
*
* @return string
*/
protected function transformTypes($types)
{
if ($types == '') {
return $types;
}

$types = explode(';', $types);
foreach ($types as $key => $type) {
$types[$key] = 'type=' . $type;
}
return implode(';', $types);
}
}
15 changes: 10 additions & 5 deletions tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function setUp()
$this->additional = '&';
$this->prefix = 'Mister';
$this->suffix = 'Junior';

$this->emailAddress1 = '';
$this->emailAddress2 = '';

Expand Down Expand Up @@ -286,11 +286,16 @@ public function testEmail($emails = [])
}
}

foreach ($emails as $key => $email) {
if (is_string($key)) {
$this->assertContains('EMAIL;INTERNET;' . $key . ':' . $email, $this->vcard->getOutput());
foreach ($emails as $types => $email) {
if (is_string($types)) {
$types = explode(';', $types);
foreach ($types as $key => $type) {
$types[$key] = 'type=' . $type;
}
$types = implode(';', $types);
$this->assertContains('EMAIL;type=INTERNET;' . $types . ':' . $email, $this->vcard->getOutput());
} else {
$this->assertContains('EMAIL;INTERNET:' . $email, $this->vcard->getOutput());
$this->assertContains('EMAIL;type=INTERNET:' . $email, $this->vcard->getOutput());
}
}
}
Expand Down