diff --git a/base.php b/base.php index 0a1030ff..be75eed3 100644 --- a/base.php +++ b/base.php @@ -34,7 +34,6 @@ defined('IS_API') or define('IS_API', false); // 是否API接口 defined('APP_AUTO_RUN') or define('APP_AUTO_RUN', true); // 是否自动运行 defined('APP_ROUTE_ON') or define('APP_ROUTE_ON', true); // 是否允许路由 defined('APP_ROUTE_MUST') or define('APP_ROUTE_MUST', true); // 是否严格检查路由 -defined('CLASS_APPEND_SUFFIX') or define('CLASS_APPEND_SUFFIX', false); // 是否追加类名后缀 defined('APP_MODE') or define('APP_MODE', 'common'); // 应用模式 默认为普通模式 // 环境常量 diff --git a/convention.php b/convention.php index 793f02ed..7c906b80 100644 --- a/convention.php +++ b/convention.php @@ -35,8 +35,10 @@ return [ 'default_filter' => '', // 默认语言 'default_lang' => 'zh-cn', - // 是否启用控制器类后缀 - 'use_controller_suffix' => false, + // 应用类库后缀 + 'class_suffix' => false, + // 控制器类后缀 + 'controller_suffix' => false, // +---------------------------------------------------------------------- // | 模块设置 diff --git a/library/think/App.php b/library/think/App.php index 36130f09..b6e28404 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -49,6 +49,11 @@ class App */ public static $namespace = 'app'; + /** + * @var bool 应用类库后缀 + */ + public static $suffix = false; + /** * 执行应用程序 * @access public @@ -271,7 +276,7 @@ class App Hook::listen('module_init', $request); try { - $instance = Loader::controller($controller, $config['url_controller_layer'], $config['use_controller_suffix'], $config['empty_controller']); + $instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']); // 获取当前操作名 $action = $actionName . $config['action_suffix']; @@ -306,7 +311,8 @@ class App if (empty(self::$init)) { // 初始化应用 $config = self::init(); - + self::$suffix = $config['class_suffix']; + // 应用调试模式 self::$debug = Config::get('app_debug'); if (!self::$debug) { diff --git a/library/think/Build.php b/library/think/Build.php index 6ea1b755..c1806680 100644 --- a/library/think/Build.php +++ b/library/think/Build.php @@ -16,11 +16,12 @@ class Build /** * 根据传入的build资料创建目录和文件 * @access protected - * @param array $build build列表 + * @param array $build build列表 * @param string $namespace 应用类库命名空间 + * @param bool $suffix 类库后缀 * @return void */ - public static function run(array $build = [], $namespace = 'app') + public static function run(array $build = [], $namespace = 'app', $suffix = false ) { // 锁定 $lockfile = APP_PATH . 'build.lock'; @@ -38,7 +39,7 @@ class Build self::buildFile($list); } else { // 创建模块 - self::module($module, $list, $namespace); + self::module($module, $list, $namespace, $suffix); } } // 解除锁定 @@ -86,9 +87,10 @@ class Build * @param string $module 模块名 * @param array $list build列表 * @param string $namespace 应用类库命名空间 + * @param bool $suffix 类库后缀 * @return void */ - public static function module($module = '', $list = [], $namespace = 'app') + public static function module($module = '', $list = [], $namespace = 'app', $suffix = false) { $module = $module ? $module : ''; if (!is_dir(APP_PATH . $module)) { @@ -99,7 +101,7 @@ class Build // 创建配置文件和公共文件 self::buildCommon($module); // 创建模块的默认页面 - self::buildHello($module, $namespace); + self::buildHello($module, $namespace, $suffix); } if (empty($list)) { // 创建默认的模块目录和文件 @@ -130,9 +132,9 @@ class Build // 生成相关MVC文件 foreach ($file as $val) { $val = trim($val); - $filename = $modulePath . $path . DS . $val . (CLASS_APPEND_SUFFIX ? ucfirst($path) : '') . EXT; + $filename = $modulePath . $path . DS . $val . ($suffix ? ucfirst($path) : '') . EXT; $namespace = $namespace . '\\' . ($module ? $module . '\\' : '') . $path; - $class = $val . (CLASS_APPEND_SUFFIX ? ucfirst($path) : ''); + $class = $val . ($suffix ? ucfirst($path) : ''); switch ($path) { case 'controller': // 控制器 $content = "