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');



     ?>

  • 相关阅读:
    面向对象与类
    引用数据类型
    方法
    java for 语句的用法
    java 数组
    Scanner与Random
    java基本语法
    java介绍及安装。
    数据库设计
    NFS相关、NFS服务端安装配置、exportfs命令、nfs客户端的问题
  • 原文地址:https://www.cnblogs.com/handongyu/p/8867342.html
Copyright © 2011-2022 走看看