eibon 2 Denunciar post Postado Dezembro 4, 2008 Editado: (novo) - dirManip.class.php: <?php class dirManip { public static function getSomeDirsFrom($dir){ $dirs = array(); $sc = scandir($dir); if(!$sc){ return 0; } while($c =& current($sc)){ if(substr_count($c, '.') == 0){ $dirs[] = $dir.'\\'.$c; } next($sc); } return $dirs; } public static function getAllDirsFrom($dir){ $d = self::getSomeDirsFrom($dir); $d3 = array(); while($c =& current($d)){ $d2 = self::getAllDirsFrom($c); $d3 = array_merge($d3, $d2); next($d); } return array_merge($d, $d3); } } ?> autoload: <?php $rootPath = $_SERVER['DOCUMENT_ROOT']; require_once $rootPath.'/classes/dirManip.class.php'; function __autoload($className){ $file = $className.'.class.php'; $classPath = $rootPath.'/classes/'; if(file_exists($classPath.$file)){ require $classPath.$file; return; } $dirs = dirManip::getAllDirsFrom($classPath); while($c =& current($dirs)){ if(file_exists($c.$file)){ require $c.$file; return; } next($dirs); } trigger_error('O arquivo '.$className.'.class.php não foi encontrado', E_USER_WARNING); } ?> <?php class logManip { public static function writeLog($log, $content){ $fp = fopen($log, 'w'); if($fp){ $fw = fwrite($log, $content); if($fw) return 1; } return 0; } public static function readLog($log){ $c = file_get_contents($log); if($c) return $c."\n"; } public static function writeInLog($log, $content){ return self::writeLog($log, $content.self::readLog($log)); } } ?> errorHandler.php: <?php $rootPath = $_SERVER['DOCUMENT_ROOT']; require_once $rootPath.'/classes/logManip.class.php'; //Descomentar se tiver smarty...e o colocar do jeito demonstrado //require_once $rootPath.'/libaries/Smarty/Smarty.class.php'; function handleError($errno, $errstr, $errfile, $errline, $errcontext){ $message = 'Ocorreu um erro no script '.$errfile.nl2br("\n"); $logContent = $message."\n".'Erro:'.$errstr."\n".'Linha:'.$errline."\n".'Contexto:'.$errcontext."\n".str_repeat('-', 40); if(logManip::writeInLog('errors.txt', $logContent)){ $message .= 'Os administradores foram informados sobre o mesmo.'; } else { $message .= 'Favor informar os administradores sobre o mesmo.'; } /* $smarty = new Smarty(); $smarty->assign('erro', $message); $smarty->display('erro.html'); exit(0); */ die($message); } ?> erro.html: <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br"> <head> <title>[Erro]</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css" media="all"> <!-- body { background-color: #C1CDC1; } h2 { color: #ff0000; } p { color: #FF8C69; } --> </style> </head> <body> <h2>Erro</h2> <p>{$erro}</p> </body> </html> Espero que ajude o pessoal! Compartilhar este post Link para o post Compartilhar em outros sites