Skip to content

Commit

Permalink
Issue nuovo#27, support for X-* keys
Browse files Browse the repository at this point in the history
  • Loading branch information
xtsimpouris committed Apr 17, 2017
1 parent 33349c6 commit 92d4774
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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

0 comments on commit 92d4774

Please sign in to comment.