parece que llegue algo tarde a la casa para escribir algo mas elaborado, aqui lo dejo. Cluster, ojala lo puedas probar, de antemano disculpas por algun error que se me haya pasado por ahi, pero esperemos que no
Código PHP:
/**
* This class has as goal, allow to use different FPDF extensions. Its created to work under PHP4
*/
class FpdfExtensionsHandler
{
/**
* FPDF main object
* @var object class FPDF
* @final
* @access public
*/
var $fpdf = null;
/**
* save the variables of the FPDF class
* @var Array
* @final
* @access private
*/
var $fpdf_vars = null;
/**
* save references to the loaded extensions
* @var Array
* @final
* @access private
*/
var $extensions_references = array();
/**
* save the extensions vars
* @var Array
* @final
* @access private
*/
var $extensions_vars = array();
/**
* default directory to search the extensions
* @var String
* @final
* @accesss private
*/
var $default_extensions_dir = './';
/**
* here can pass as many arguments as needed for the Fpdf constructor
* @return bool
* @param Mixed $FpdfConstructorArugment1
* @param Mixed $FpdfConstructorArugment2
* @param Mixed $FpdfConstructorArugmentN...
* @final
* @access public
*/
function FpdfExtensionHandler()
{
if ( class_exists('FPDF') )
{
//getting FPDF vars
$this->fpdf_vars = get_class_vars('FPDF');
//create FPDF instance
$arguments = func_get_args();
$string_arguments = "";
foreach ( $arguments as $index => $argument )
{
$string_arguments .= "\$arguments[$index], ";
}
$string_arguments = substr($string_arguments,0,strlen($string_arguments) - 2);
$eval_code = "\$this->fpdf = new FPDF({$string_arguments});";
eval($eval_code);
return true;
}
else
{
die("Missing class FPDF!");
}
}
/**
* Try to load a new extension
* @return bool
* @param String $ExtensionName
* @param String $ExtensionDirectory
* @param Mixed $ExtensionConstructorArg1
* @param Mixed $ExtensionConstructorArg2
* @param Mixed $ExtensionConstructorArgN...
* @final
* @acces public
*/
function LoadExtension($ExtensionName, $ExtensionDirectory = null)
{
$ExtensionName = (string)$ExtensionName;
$ExtensionDirectory = $ExtensionDirectory === null
? null
: (string)$ExtensionDirectory;
$class_file = $ExtensionDirectory === null
? $this->default_extensions_dir.$ExtensionName
: $ExtensionDirectory.$ExtensionName;
if ( file_exists($class_file) )
{
include_once $class_file;
if ( !class_exists($ExtensionName) )
{
die("Class '{$class_file}' does not exists in file '{$class_file}'!");
}
else
{
//getting extension constructor arguments
$arguments = func_get_args();
$num_args = count($arguments);
$string_args = "";
for ( $i = 2; $i < $num_args; $i++ )
{
$string_args .= "\$arguments[$i], ";
}
$string_args = substr($string_args,0,strlen($string_args) - 2);
$eval_code = "\$this->extensions_references[\$ExtensionName] =& new \$ExtensionName($string_args);"
eval($eval_code);
if ( !is_subclass_of($this->extensions_references[$ExtensionName], 'FPDF') )
{
die("Class '{$ExtensionName}' is not a subclass of FPDF!");
}
else
{
$this->extensions_vars[$ExtensionName] = array();
$this->extensions_vars[$ExtensionName] = get_class_vars($ExtensionName);
$this->MergeExtensions();
return true;
}
}
}
else
{
die("Unable to open class file '{$class_file}'!");
}
}
/**
* Merge the loaded extensions variables, so every instance will edit the same variables
* @return bool
* @param void
* @final
* @acces private
*/
function MergeExtensionsVars()
{
foreach ( $this->extensions_vars as $class_name => $class_vars )
{
foreach ( $class_vars as $variable_name )
{
if ( array_key_exists($variable_name, $this->fpdf_vars) )
{
$this->extensions_references[$class_name]->$variable_name =& $this->fpdf->$variable_name;
}
}
}
}
/**
* Change the default directory for extensions
* @return bool
* @param String $DirectoryName
* @final
* @acces public
*/
function SetDefaultExtensionDir($DirectoryName)
{
$this->default_extensions_dir = (string)$DirectoryName;
return true;
}
/**
* Change the working extension
* @return bool
* @param String $ExtensionName
* @final
* @acces public
*/
function SetExtension($ExtensionName)
{
$ExtensionName = (string)$ExtensionName;
if ( array_key_exists($ExtensionName) )
{
$this->extension =& $this->extensions_references[$ExtensionName];
return true;
}
{
die("Extension '{$ExtensionName}' does not has been loaded yet!");
}
}
}