note 44111 deleted from ref.pdf by didou
| From: | didou@php.net | Date: | Wed, 24 Jan 2007 07:46:00 +0000 |
| Subject: | note 44111 deleted from ref.pdf by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122109@lists.php.net to get a copy of this message | ||
Note Submitter: arjen at queek dot nl
----
If you prefer a OO-approach to the PDF-functions, you can use this snippet of code (PHP5 only! and
does add some overhead). It's just a "start-up", extend/improve as you wish...
You can pass all pdf_* functions to your object and stripping pdf_ of the function name. Plus, you
don't have to pass the pdf-resource as the first argument.
For example:
<?php
pdf_show($pdf, $text); // Where $pdf is your pdf-resource
?>
Can become:
<?php
$pdf->show($text); // Where $pdf is your PDF-object
?>
Code:
<?php
class PDF {
private $pdf;
/* public Void __construct(): Constructor */
public function __construct() {
$this->pdf = pdf_new();
}
/* public Mixed __call(): Re-route all function calls to the PHP-functions */
public function __call($function, $arguments) {
// Prepend the pdf resource to the arguments array
array_unshift($arguments, $this->pdf);
// Call the PHP function
return call_user_func_array('pdf_' . $function, $arguments);
}
}
?>