<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### :-: 編寫路由配置加載方法 ~~~php <?php namespace App\Lib; use App\Exception\MethodNotAllowedException; use App\Exception\RouteNotFoundException; use FastRoute\Dispatcher; use FastRoute\RouteCollector; use function FastRoute\simpleDispatcher; class Route { public static function load() { // 獲取已配置的路由列表 $routeFiles = glob(ROUTE_PATH.DIRECTORY_SEPARATOR.'*.php'); foreach ($routeFiles as $file) { $routeFileList[] = require_once($file); } // 加載所有路由文件配置的路由 $dispatcher = self::make_dispatcher($routeFileList); // Fetch method and URI from somewhere $httpMethod = $_SERVER['REQUEST_METHOD']; $uri = $_SERVER['REQUEST_URI']; // Strip query string (?foo=bar) and decode URI if (false !== $pos = strpos($uri, '?')) { $uri = substr($uri, 0, $pos); } $uri = rawurldecode($uri); // 路由調度 $routeInfo = $dispatcher->dispatch($httpMethod, $uri); switch ($routeInfo[0]) { case Dispatcher::NOT_FOUND: // 找不到請求方法 // ... 404 Not Found throw new RouteNotFoundException("請求方法不存在:{$uri}"); break; case Dispatcher::METHOD_NOT_ALLOWED: // 請求類型錯誤 $allowedMethods = $routeInfo[1]; // ... 405 Method Not Allowed throw new MethodNotAllowedException("請求類型錯誤({$httpMethod}),當前方法允許請求類型({$allowedMethods[0]})"); break; case Dispatcher::FOUND: // 找到請求方法:調用方法即可 $handler = $routeInfo[1]; $vars = $routeInfo[2]; call_user_func([new $handler[0],$handler[1]],$vars); break; } } private static function make_dispatcher($routeFileList) { return simpleDispatcher(function(RouteCollector $router) use($routeFileList) { foreach ($routeFileList as $routeFile) { if (isset($routeFile['prefix'])) { $routers = $routeFile[0]; $router->addGroup($routeFile['prefix'],function(RouteCollector $router) use($routers) { if ($routers) { foreach ($routers as $routeItem) { $router->addRoute(strtoupper($routeItem[0]),$routeItem[1],$routeItem[2]); } unset($routeItem); } }); } else { if ($routeFile) { foreach ($routeFile as $routeItem) { $router->addRoute(strtoupper($routeItem[0]),$routeItem[1],$routeItem[2]); } unset($routeItem); } } } unset($routeFile); }); } } ~~~ ### :-: 涉及到的exception類寫法 ~~~php <?php namespace App\Exception; use Throwable; class MethodNotAllowedException extends \Exception { public function __construct($message = "", $code = 0, Throwable $previous = null) { parent::__construct($message, $code, $previous); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看