Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.3.3

Request #12441 Additional parameters
Submitted: 2007-11-14 09:04 UTC
From: garivin Assigned: chagenbu
Status: Closed Package: File_PDF (version 0.3.1)
PHP Version: 5.2.3 OS: windows XP
Roadmaps: (Not assigned)    
Subscription  


 [2007-11-14 09:04 UTC] garivin (Javier Mestre)
Description: ------------ Add the possibility to add parameters to the child class when you use File_PDF factory method ? ie. require('File/PDF.php'); class PDF_Label extends File_PDF .... .... $pdf = PDF_Label::factory(array('orientation' => 'P', 'unit' => 'mm', 'format' => 'A4'), 'PDF_Label' ,array('L7163',1,2)); This is a modification of Label script from fpdf site (http://www.fpdf.org/en/script/script29.php)

Comments

 [2007-11-15 08:13 UTC] garivin (Javier Mestre)
One solution that works for me is (borrowed from Image_Graph Pear package) function &factory($params = array(), $class = 'File_PDF',$additional=null) ........ ........ /* Create the PDF object. */ //<JMS> if (is_array($additional)) { switch (count($additional)) { case 1: $pdf =& new $class( $additional[0] ); break; case 2: $pdf =& new $class( $additional[0], $additional[1] ); break; case 3: $pdf =& new $class( $additional[0], $additional[1], $additional[2] ); break; case 4: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3] ); break; case 5: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4] ); break; case 6: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4], $additional[5] ); break; case 7: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4], $additional[5], $additional[6] ); break; case 8: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4], $additional[5], $additional[6], $additional[7] ); break; case 9: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4], $additional[5], $additional[6], $additional[7], $additional[8] ); break; case 10: $pdf =& new $class( $additional[0], $additional[1], $additional[2], $additional[3], $additional[4], $additional[5], $additional[6], $additional[7], $additional[8], $additional[9] ); break; default: $pdf =& new $class(); break; } } else { if ($additional == null) { $pdf =& new $class(); } else { $pdf =& new $class($additional); } } //</JMS> //$pdf = new $class(); Hope this helps
 [2007-11-19 03:40 UTC] chagenbu (Chuck Hagenbuch)
That switch/case gives me hives with the hardcoding and extra lines of code for something so simple. How about just passing $params to the constructor and letting it handle anything extra it wants to?
 [2007-11-19 10:04 UTC] garivin (Javier Mestre)
Yes, I know that I need only the last few lines: if ($additional == null) { $pdf =& new $class(); } else { $pdf =& new $class($additional); } and manage $additional in the PDF_Label constructor but, as I'm testing all the additional scripts you can find in fpdf site (translating them to File_Pdf), I try to change as less logic as I can. In any case, one solution like the previous one would be good for me. Thanks
 [2007-11-19 16:55 UTC] chagenbu (Chuck Hagenbuch)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I've committed the change to pass $params to the constructor. Exact compatibility with fpdf is not a goal or requirement for File_PDF. Btw, if you are porting examples to File_PDF, though, could you please contribute them? Would be great to have in the base package to provide to users.
 [2007-11-19 20:07 UTC] garivin (Javier Mestre)
Thanks for the new feature. I'm trying to contact the scripts owners, just to add credits for them (base on a script from....). Let me know how I can send you the working examples (some of them still need some rework)
 [2007-11-19 20:25 UTC] chagenbu (Chuck Hagenbuch)
You can upload them to http://bugs.horde.org/ as attachments (if there are a lot, preferably a zip/tar file) in a bug in the Horde Framework queue, or you can send them directly to me (email is on the pear userinfo page that should be linked from this comment). Thanks!