/** * Recursive Require Once * * Recursively searches the path for the class, require_once if found. * * @param string $class Name of class to look for * @param string $path Current path to search */ protected static function recursive_require_once($class, $path) { $found = FALSE; if (is_dir($path)) { $handle = opendir($path); if ($handle) { while (FALSE !== ($dir = readdir($handle))) { // If dir does not contain a dot if (strpos($dir, '.') === FALSE) { // Prepare recursive path $recursive_path = $path . '/' . $dir; // Prepare file $file = $recursive_path . '/' . $class . EXT; // Check if file exists, require_once if it does if (file_exists($file)) { require_once $file; $found = TRUE; break; } else { if (is_dir($recursive_path)) { // Do a recursive search of the path for the class DataMapper::recursive_require_once($class, $recursive_path); } } } } closedir($handle); } } return $found; }
static function autoload($class) { // Don't attempt to autoload CI_ or MY_ prefixed classes if (in_array(substr($class, 0, 3), array('CI_', 'MY_'))) { return; } // Prepare class $class = strtolower($class); // Prepare path $path = APPPATH . 'modules'; if (is_dir($path)) { if ($handle = opendir($path)) { while (FALSE !== ($dir = readdir($handle))) { // If dir does not contain a dot if (strpos($dir, '.') === FALSE) { $modules[] = $dir; } } } } foreach ($modules as $module) { // Prepare path $path = APPPATH . 'modules/' . $module . '/models'; // Verify if there is a models folder on Module folder if (is_dir($path)) { // Prepare file $file = $path . '/' . $class . EXT; // Check if file exists, require_once if it does if (file_exists($file)) { require_once $file; } else { // Do a recursive search of the path for the class DataMapper::recursive_require_once($class, $path); } } } }