Ciao a tutti,
Per la mia applicazione ho creato un piccolo autoloder per le mie classi:
Codice PHP:
define("ROOT", "/service/Test/");
function __autoload($class) {
$class = str_replace("_","/",$class);
include ROOT.'lib/' . $class . '.php';
}
Ho iniziato ad aver problemi quando ho integrato la classe PHPExcell
require_once('lib/PHPExcel/PHPExcel.php');
in pratica questa classe definisce a sua volta un suo autoloder
Codice PHP:
PHPExcel_Autoloader::Register();
// As we always try to run the autoloader before anything else, we can use it to do a few
// simple checks and initialisations
//PHPExcel_Shared_ZipStreamWrapper::register();
// check mbstring.func_overload
if (ini_get('mbstring.func_overload') & 2) {
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
}
PHPExcel_Shared_String::buildCharacterSets();
/**
* PHPExcel_Autoloader
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Autoloader
{
/**
* Register the Autoloader with SPL
*
*/
public static function Register() {
if (function_exists('__autoload')) {
// Register any existing autoloader function with SPL, so we don't get any clashes
spl_autoload_register('__autoload');
}
// Register ourselves with SPL
return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
} // function Register()
/**
* Autoload a class identified by name
*
* @param string $pClassName Name of the object to load
*/
public static function Load($pClassName){
if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
// Either already loaded, or not a PHPExcel class request
return FALSE;
}
$pClassFilePath = PHPEXCEL_ROOT .
str_replace('_',DIRECTORY_SEPARATOR,$pClassName) .
'.php';
if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
// Can't load
return FALSE;
}
require($pClassFilePath);
} // function Load()
}
il problema sopraggiunge con questa dichiarazione
PHPExcel_Shared_String::buildCharacterSets();
il mio autoloder non lo trova... ovviamente.
la classe è localizzata in lib/PHPExcell/PHPExcell/Shared/String.php
Ma io da grande risolutore con le cose più strane ho trovato una soluzione...
Voglio vedere quanti insulti posso ricevere...
Codice PHP:
function __autoload($class) {
$class = str_replace("_","/",$class);
if(!strstr($class,"PHPExcel"))
include ROOT.'lib/' . $class . '.php';
}
Scherzi a parte, quali altre soluzioni posso avere?
Grazie a tutti ciao a tutti