From 92d4774035ceae081d5a501f0b65499364aaa41a Mon Sep 17 00:00:00 2001 From: Charalampos Tsimpouris Date: Mon, 17 Apr 2017 17:57:19 +0300 Subject: [PATCH] Issue #27, support for X-* keys --- README.md | 2 ++ vCard.php | 19 ++++++++++++++++++- write-test.php | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6638fb..276bbd5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/vCard.php b/vCard.php index b2f0476..28ede9c 100644 --- a/vCard.php +++ b/vCard.php @@ -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])) @@ -513,7 +530,7 @@ private static function PrepareTypeStrForOutput($Type) return implode(',', array_map('strtoupper', $Type)); } - /** + /** * Removes the escaping slashes from the text. * * @access private diff --git a/write-test.php b/write-test.php index 5938390..ee09879 100644 --- a/write-test.php +++ b/write-test.php @@ -14,6 +14,8 @@ $vCard -> adr('30314', 'PostalCode'); $vCard -> adr('USA', 'Country'); + $vCard -> setAttr('X-GENERIC', 'Dummy'); + //$vCard = new vCard('Example3.0.vcf'); echo '
'.$vCard.'
';