From f10353bee67fdb8ebcea8787a1b2e0d44aabeebd Mon Sep 17 00:00:00 2001 From: ljl Date: Wed, 31 Jan 2024 09:52:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/libs/exception/RouteNotFoundException.php | 8 -- app/libs/tool/Route.php | 82 -------------- app/libs/tool/RouteManager.php | 103 ------------------ app/libs/tool/class.AppUrlHandler.php | 34 +++++- app/routes/route.php | 7 -- 5 files changed, 30 insertions(+), 204 deletions(-) delete mode 100644 app/libs/exception/RouteNotFoundException.php delete mode 100644 app/libs/tool/Route.php delete mode 100644 app/libs/tool/RouteManager.php delete mode 100644 app/routes/route.php diff --git a/app/libs/exception/RouteNotFoundException.php b/app/libs/exception/RouteNotFoundException.php deleted file mode 100644 index 06f9031..0000000 --- a/app/libs/exception/RouteNotFoundException.php +++ /dev/null @@ -1,8 +0,0 @@ - $actionRoute, - 'methods' => $methods, - 'middlewares' => $options['middlewares'] ?: [] - ]; - } - - public static function group($groupUri, $callback, $moudle = '', $options = []) { - self::$groupUri = $groupUri; - $callback(); - self::$groupUri = ''; - } - - public static function getRouteMap() { - return self::$routeMap; - } - - private static function getRouteByAction($action, $moudle = '') { - $action = trim($action, '/'); - $actionItems = explode('/', $action); - $moudle = trim($moudle, '/'); - $route = $moudle ? '/' . $moudle . '/' : '/'; - foreach ($actionItems as $item) { - if (strpos($item, '@') !== false) { - list($controller, $method) = explode('@', $item); - $controller = str_replace('Controller', '', $controller); - $route .= self::toUnderScore($controller. '/' . $method); - } else { - $route .= $item . '/'; - } - } - return $route; - } - - private static function toUnderScore($str) { - $dstr = preg_replace_callback('/([A-Z])/', function ($matchs) { - return '_' . strtolower($matchs[0]); - }, $str); - return trim(preg_replace('/_{2,}/', '_', $dstr), '_'); - } -} \ No newline at end of file diff --git a/app/libs/tool/RouteManager.php b/app/libs/tool/RouteManager.php deleted file mode 100644 index 145e37d..0000000 --- a/app/libs/tool/RouteManager.php +++ /dev/null @@ -1,103 +0,0 @@ -routeConfigPath = $routeConfigPath; - } else { - $this->routeConfigPath = APP_PATH . '/routes'; - } - $this->initRoutes(); - } - - public function rewrite($route) { - $routeMap = Route::getRouteMap(); - $routeInfo = $routeMap[$route]; - $route = $routeInfo ? $routeInfo['actionRoute'] : $route; - $this->checkMethodAllow($routeInfo['methods']); - $this->checkActionExists($route); - return $route; - } - - private function checkMethodAllow($allowMethods) { - $allowMethods = ['get', 'post']; - array_walk($allowMethods, function(&$value) { - $value = strtoupper($value); - }); - if(!in_array(strtoupper($_SERVER['REQUEST_METHOD']), $allowMethods)) { - throw new MethodNotAllowException('Method not allow.'); - } - } - - private function checkActionExists($route) { - $routeItems = explode('/', trim($route, '/')); - $routeItemLen = count($routeItems); - if ($routeItemLen < 2) { - throw new RouteNotFoundException('Route[' . $route . '] can not parse.'); - } - $action = $routeItems[$routeItemLen - 1]; - $controller = $routeItems[$routeItemLen - 2]; - - $pathItems = array_slice($routeItems, 0, $routeItemLen - 2); - $controllerPath = ''; - if (!empty($pathItems)) { - $controllerPath = implode('/', $pathItems); - } - - $controllerDir = Zc::C(ZcConfigConst::DirFsLibsController); - $controllerClass = ucfirst($this->toCamel($controller)) . 'Controller'; - $controllerFile = $controllerPath . '/' . 'class.' . $controllerClass . '.php'; - if (!is_file($controllerDir . $controllerFile)) { - throw new RouteNotFoundException('Can nott find controller[' . $controllerFile . '].'); - } - - require_once($controllerDir . $controllerFile); - - $reflection = new ReflectionClass($controllerClass); - if (!$reflection->hasMethod($this->toCamel($action))) { - throw new RouteNotFoundException('Can nott find method[' . $action . '] in ' . $controllerFile . '.'); - } - } - - private function initRoutes() { - $files = $this->getDirFiles($this->routeConfigPath); - foreach ($files as $file) { - require $file; - } - } - - private function getDirFiles($path) { - $files = []; - if(is_dir($path)) { - $dir = scandir($path); - foreach($dir as $value) { - $file = $path . '/'. $value; - if ($value == '.' || $value == '..') { - continue; - } elseif (is_dir($file)) { - $files = array_merge($files, getDir($file)); - } else { - $files[] = $file; - } - } - } - return $files; - } - - private function toCamel($str) { - $array = explode('_', $str); - $result = $array[0]; - $len = count($array); - if ($len > 1) { - for ($i = 1; $i < $len; $i++) { - $result .= ucfirst($array[$i]); - } - } - return $result; - } -} \ No newline at end of file diff --git a/app/libs/tool/class.AppUrlHandler.php b/app/libs/tool/class.AppUrlHandler.php index c31f2f0..9bfa602 100644 --- a/app/libs/tool/class.AppUrlHandler.php +++ b/app/libs/tool/class.AppUrlHandler.php @@ -1,7 +1,5 @@ rewrite($route), '/'); + $route = trim($route, '/'); + + if (AppConst::isUseAppModuleApp() && (stripos($route, 'control/decrypt/') === 0)) { + return 'pdd/' . $route; + } + + if ((AppConst::isPddRubyApp() || AppConst::isPddTaoBaiKeApp()) && $this->isUseRealRoute($route)) { + return $route; + } + if (AppConst::isRubyWeb()) { + if (stripos($route, 'ruby/') === 0) { + return $route; + } else { + return 'ruby/' . $route; + } + } else if (AppConst::isRubyDesktop()) { + if (stripos($route, 'ruby_dt/') === 0) { + return $route; + } else { + return 'ruby_dt/' . $route; + } + } else if (AppConst::isPddTaoBaiKeApp()) { + if (stripos($route, 'taobaike/') === 0) { + return $route; + } else { + return 'taobaike/' . $route; + } + } + + return $route; } private function isUseRealRoute($route){ diff --git a/app/routes/route.php b/app/routes/route.php deleted file mode 100644 index 9cb9f10..0000000 --- a/app/routes/route.php +++ /dev/null @@ -1,7 +0,0 @@ - [], 'apps' => []]); - Route::get('/order-print-test', 'OrderPrintController@test'); - Route::get('/dgfdgs/sdfs', 'OrderPrintController@test'); -}, 'order', ['middleware' => []]); \ No newline at end of file