$dir) { if ($dir == '.') { $dirs[$key] = $dirPath; } else { $dir = rtrim($dir, '\\/'); $dirs[$key] = $dir . DIRECTORY_SEPARATOR . $dirPath; } } $file = basename($file); Zeed_Loader::loadFile($file, $dirs, true); } else { // Zeed / Zend, high priority if (($suffix = substr($class, 0, 5)) === 'Zeed_' || $suffix === 'Zend_') { $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; if (file_exists(ZEED_PATH . $file)) { include_once ZEED_PATH . $file; return; } elseif ($suffix === 'Zend_') { include_once $file; return; } } // Load the file named same as class name. if (null != $file = Zeed_Loader::findFile($class . EXT)) { include_once $file; if (class_exists($class, false) || interface_exists($class, false)) { self::saveClassIndex($class, $file); return; } } // Controller, Model, Entity, View $m = array(); if (is_null($dirs) && preg_match("/([A-Z0-9]{1,})(Controller|Model|Entity|Object|Hook|View)$/i", $class, $m)) { $file = $m[1] . EXT; if (null != $file = Zeed_Loader::findFile($file, $m[2])) { include_once $file; if (class_exists($class, false) || interface_exists($class, false)) { self::saveClassIndex($class, $file); return; } } } // Parse class name to folder. if (strstr($class, '_')) { $file = str_replace('_', '/', $class) . EXT; if (null != $file = Zeed_Loader::findFile($file)) { include_once $file; if (class_exists($class, false) || interface_exists($class, false)) { self::saveClassIndex($class, $file); return; } } } } if (! class_exists($class, false) && ! interface_exists($class, false)) { Zeed_Loader::loadClass('Zeed_Exception'); throw new Zeed_Exception("File \"$file\" does not exist or class \"$class\" was not found in the file"); } } private static $__CLASSINDEXING = null; private static function loadClassFormClassIndex($classname) { if (is_null(self::$__CLASSINDEXING)) { if (file_exists(ZEED_PATH_DATA . 'cache/__CLASSINDEXING.php')) { self::$__CLASSINDEXING = include ZEED_PATH_DATA . 'cache/__CLASSINDEXING.php'; /** * 确保变量为数组 * * @see /manual/en/function.include.php */ if (!is_array(self::$__CLASSINDEXING)) { self::$__CLASSINDEXING = array(); } } else { return null; } } if (is_array(self::$__CLASSINDEXING) && isset(self::$__CLASSINDEXING[$classname])) { /** * 如果优先查找模块 */ if (defined('ZEED_PATH_MODULE')) { $moduleFolderName = basename(ZEED_PATH_MODULE); if (is_array(self::$__CLASSINDEXING[$classname])) { if (isset(self::$__CLASSINDEXING[$classname][$moduleFolderName])) { return self::$__CLASSINDEXING[$classname][$moduleFolderName]; } else { reset(self::$__CLASSINDEXING[$classname]); return current(self::$__CLASSINDEXING[$classname]); } } } return self::$__CLASSINDEXING[$classname]; } return null; } private static function saveClassIndex($classname, $filepath) { if (defined('ZEED_PATH_MODULE') && strstr($filepath, ZEED_PATH_MODULE)) { // 子模块的CLASS $moduleFolderName = basename(ZEED_PATH_MODULE); self::$__CLASSINDEXING[$classname][$moduleFolderName] = (string) $filepath; } else { // 全局的CLASS self::$__CLASSINDEXING[$classname] = (string) $filepath; } $string = " $_incPaths) { switch ($findPathsOrType) { case 'Object' : $filepath = rtrim($_incPaths['entity'], '\\/') . '/' . $filename; break; case 'Enity' : $filepath = rtrim($_incPaths['entity'], '\\/') . '/' . $filename; break; case 'Model' : $filepath = rtrim($_incPaths['model'], '\\/') . '/' . $filename; break; case 'Hook' : $filepath = rtrim($_incPaths['hook'], '\\/') . '/' . $filename; break; case 'Controller' : $filepath = rtrim($_incPaths['controller'], '\\/') . '/' . $filename; break; } if (file_exists($filepath)) { return $filepath; } } } } if (is_array($findPathsOrType) && count($findPathsOrType) > 0) { foreach ($findPathsOrType as $dir) { /* 临时解决方案 - 设计了模块控制器中集成后台和前台目录的功能 */ if (strstr($filename, 'Abstract.php')) { $dir_arr_temp = explode('/', $dir); if ($dir_arr_temp[count($dir_arr_temp) - 3] == 'controllers') { unset($dir_arr_temp[count($dir_arr_temp) - 2], $dir_arr_temp[count($dir_arr_temp) - 1], $dir_arr_temp[count($dir_arr_temp)]); $dir = implode('/', $dir_arr_temp); } } /* 临时解决方案 - 设计了模块控制器中集成后台和前台目录的功能 @end 2013-07-14 */ if (file_exists($filepath = rtrim($dir, '\\/') . '/' . $filename)) { return $filepath; } } } return null; } /** * @param string $modulename */ public static function addModulePath($modulename) { $_incPaths = Zeed::registry('ZEED_INCLUDE_PATH'); if (! isset($_incPaths[$modulename])) { $moduleFolder = ZEED_PATH_APPS . $modulename . '/'; $_incPaths[$modulename] = array( 'library' => realpath($moduleFolder . 'libraries/'), 'model' => realpath($moduleFolder . 'models/'), 'entity' => realpath($moduleFolder . 'entities/'), 'controller' => $moduleFolder . 'controllers/'); set_include_path(implode(PATH_SEPARATOR, $_incPaths[$modulename]) . PATH_SEPARATOR . get_include_path()); Zeed::register($_incPaths, 'ZEED_INCLUDE_PATH'); } } } // End ^ LF ^ UTF-8