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

Issue #27, support for X-* keys #32

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ In the single-vCard mode every element is accessible directly.
print_r($vCard -> tel);
}

In order to support generic keys, like X-*, use the method setAttr instead.

In the multiple-vCard mode the object can be used as an array to retrieve separate vCard objects for each vCard in the file.

else
Expand Down
19 changes: 18 additions & 1 deletion vCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,23 @@ public function SaveFile($Key, $Index = 0, $TargetPath = '')
*/
public function __call($Key, $Arguments)
{
$args = array_merge(array($Key), $Arguments);
return call_user_func_array(array($this, 'setAttr'), $args);
}

/**
* Method for adding data to the vCard, made generic fo wierd tags like X-*
*
* @param string Key
* @param string Method call arguments. First element is value.
*
* @return vCard Current object for method chaining
*/
public function setAttr()
{
$Arguments = func_get_args();
$Key = array_shift($Arguments);

$Key = strtolower($Key);

if (!isset($this -> Data[$Key]))
Expand Down Expand Up @@ -513,7 +530,7 @@ private static function PrepareTypeStrForOutput($Type)
return implode(',', array_map('strtoupper', $Type));
}

/**
/**
* Removes the escaping slashes from the text.
*
* @access private
Expand Down
2 changes: 2 additions & 0 deletions write-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
$vCard -> adr('30314', 'PostalCode');
$vCard -> adr('USA', 'Country');

$vCard -> setAttr('X-GENERIC', 'Dummy');

//$vCard = new vCard('Example3.0.vcf');

echo '<pre>'.$vCard.'</pre>';
Expand Down