zoukankan      html  css  js  c++  java
  • LARAVEL 路由原理分析

    <?php


    class App {
        protected $routes = [];
        protected $responseStatus = '200 OK';
        protected $responseContentType = 'text/html';
        protected $responseBody = 'Laravel学院';

        public function addRoute($routePath, $routeCallback) {

            $this->routes[$routePath] = $routeCallback->bindTo($this, __CLASS__);
        }

        public function dispatch($currentPath) {
            foreach ($this->routes as $routePath => $callback) {
                if( $routePath === $currentPath) {
                    $callback();
                }
            }
            header('HTTP/1.1 ' . $this->responseStatus);
            header('Content-Type: ' . $this->responseContentType);
            header('Content-Length: ' . mb_strlen($this->responseBody));
            echo $this->responseBody;
        }

    }


    $app = new App();
    $app->addRoute('user/nonfu', function(){
        $this->responseContentType = 'application/json;charset=utf8';
        $this->responseBody = '{"name":"LaravelAcademy"}';
    });
    $app->dispatch('user/nonfu');



     ?>

  • 相关阅读:
    snaker数据库表说明
    Oracle 导入、导出DMP(备份)文件
    eclipse debug无法启动
    java----事务
    java----单例模式
    java----spring框架
    mybatis----批量增加与批量删除
    web应用程序状态管理
    JavaWeb----servlet
    HTML / CSS----元素分类
  • 原文地址:https://www.cnblogs.com/handongyu/p/8867342.html
Copyright © 2011-2022 走看看