@@ -843,33 +843,49 @@ protected function negotiateVCard($input, &$mimeType = null) {
843843 /**
844844 * Converts a vcard blob to a different version, or jcard.
845845 *
846- * @param string $data
846+ * @param string|resource $data
847847 * @param string $target
848848 * @return string
849849 */
850850 protected function convertVCard ($ data , $ target ) {
851851
852- $ data = VObject \Reader::read ($ data );
853- switch ($ target ) {
854- default :
855- case 'vcard3 ' :
856- $ data = $ data ->convert (VObject \Document::VCARD30 );
857- $ newResult = $ data ->serialize ();
858- break ;
859- case 'vcard4 ' :
860- $ data = $ data ->convert (VObject \Document::VCARD40 );
861- $ newResult = $ data ->serialize ();
862- break ;
863- case 'jcard ' :
864- $ data = $ data ->convert (VObject \Document::VCARD40 );
865- $ newResult = json_encode ($ data ->jsonSerialize ());
866- break ;
867-
852+ if (is_resource ($ data )) {
853+ $ data = stream_get_contents ($ data );
868854 }
869- // Destroy circular references to PHP will GC the object.
870- $ data ->destroy ();
855+ $ input = VObject \Reader::read ($ data );
856+ $ output = null ;
857+ try {
871858
872- return $ newResult ;
859+ switch ($ target ) {
860+ default :
861+ case 'vcard3 ' :
862+ if ($ input ->getDocumentType () === VObject \Document::VCARD30 ) {
863+ // Do nothing
864+ return $ data ;
865+ }
866+ $ output = $ input ->convert (VObject \Document::VCARD30 );
867+ return $ output ->serialize ();
868+ case 'vcard4 ' :
869+ if ($ input ->getDocumentType () === VObject \Document::VCARD40 ) {
870+ // Do nothing
871+ return $ data ;
872+ }
873+ $ output = $ input ->convert (VObject \Document::VCARD40 );
874+ return $ output ->serialize ();
875+ case 'jcard ' :
876+ $ output = $ input ->convert (VObject \Document::VCARD40 );
877+ return json_encode ($ output );
878+
879+ }
880+
881+ } finally {
882+
883+ // Destroy circular references to PHP will GC the object.
884+ $ input ->destroy ();
885+ if (!is_null ($ output )) {
886+ $ output ->destroy ();
887+ }
888+ }
873889
874890 }
875891
0 commit comments