Criar exceção em autoload
Fala galera,
Tenho o seguinte autoload no PHP:
define( "CLASS_DIR", __DIR__.DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR );
spl_autoload_register( function( $class ) {
$className = CLASS_DIR.str_replace("\\", DIRECTORY_SEPARATOR, $class).".php";
include( $className );
});
if( $handle = opendir( CLASS_DIR ) ){
while( false !== ( $file = readdir( $handle ) ) ){
if( !is_dir( $file ) && $file != ".DS_Store" ){
$arrayClasses[] = str_replace( ".php", "", $file);
}
}
closedir( $handle );
}
Porém, não gostaria que o mesmo incluísse todas as classes.
Está dando problema quando tenho subdiretórios dentro do diretório /class.
Exemplo:
/class
--- ClasseTeste.php
--- /Recaptcha
-------- Recaptcha.php <- Esta poderia ser incluída, mas o autoload não a encontra.
>
Warning: include(/Applications/XAMPP/xamppfiles/htdocs/common/class/ReCaptcha.php) [function.include]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/common/autoload.php on line 15
Warning: include() [function.include]: Failed opening '/Applications/XAMPP/xamppfiles/htdocs/common/class/ReCaptcha.php' for inclusion (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear') in /Applications/XAMPP/xamppfiles/htdocs/common/autoload.phpon line 15
Como posso alterá-lo para considerar também sub-diretórios, ou se não é possível, removê-lo através de uma lista de exceções (um array talvez?).
Discussão (5)
Carregando comentários...