1<?php 2/** 3 * class autoloader 4 * 5 * PHP version 5 6 * 7 * @category PHP 8 * @package PSI 9 * @author Michael Cramer <BigMichi1@users.sourceforge.net> 10 * @copyright 2009 phpSysInfo 11 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version 12 * @version SVN: $Id: autoloader.inc.php 660 2012-08-27 11:08:40Z namiltd $ 13 * @link http://phpsysinfo.sourceforge.net 14 */ 15 16error_reporting(E_ALL | E_STRICT); 17 18/** 19 * automatic loading classes when using them 20 * 21 * @param string $class_name name of the class which must be loaded 22 * 23 * @return void 24 */ 25function psi_autoload($class_name) 26{ 27 //$class_name = str_replace('-', '', $class_name); 28 29 /* case-insensitive folders */ 30 $dirs = array('/plugins/'.strtolower($class_name).'/', '/includes/mb/', '/includes/ups/'); 31 32 foreach ($dirs as $dir) { 33 if (file_exists(PSI_APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php')) { 34 include_once PSI_APP_ROOT.$dir.'class.'.strtolower($class_name).'.inc.php'; 35 36 return; 37 } 38 } 39 40 /* case-sensitive folders */ 41 $dirs = array('/includes/', '/includes/interface/', '/includes/to/', '/includes/to/device/', '/includes/os/', '/includes/plugin/', '/includes/xml/', '/includes/web/', '/includes/error/', '/includes/js/', '/includes/output/'); 42 43 foreach ($dirs as $dir) { 44 if (file_exists(PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php')) { 45 include_once PSI_APP_ROOT.$dir.'class.'.$class_name.'.inc.php'; 46 47 return; 48 } 49 } 50 51 $error = PSI_Error::singleton(); 52 53 $error->addError("psi_autoload(\"".$class_name."\")", "autoloading of class file (class.".$class_name.".inc.php) failed!"); 54 $error->errorsAsXML(); 55} 56 57spl_autoload_register('psi_autoload'); 58 59/** 60 * sets a user-defined error handler function 61 * 62 * @param integer $level contains the level of the error raised, as an integer. 63 * @param string $message contains the error message, as a string. 64 * @param string $file which contains the filename that the error was raised in, as a string. 65 * @param integer $line which contains the line number the error was raised at, as an integer. 66 * 67 * @return void 68 */ 69function errorHandlerPsi($level, $message, $file, $line) 70{ 71 $error = PSI_Error::singleton(); 72 if (PSI_DEBUG || (($level !== 2) && ($level !== 8)) || !(preg_match("/^[^:]*: open_basedir /", $message) || preg_match("/^fopen\(/", $message) || preg_match("/^is_readable\(/", $message) || preg_match("/^file_exists\(/", $message) || preg_match("/^fgets\(/", $message))) { // disable open_basedir, fopen, is_readable, file_exists and fgets warnings and notices 73 $error->addPhpError("errorHandlerPsi : ", "Level : ".$level." Message : ".$message." File : ".$file." Line : ".$line); 74 } 75} 76 77set_error_handler('errorHandlerPsi'); 78