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

?>

最新文章

  1. 一个基于RBAC0的通用权限设计清单
  2. Evaluate Reverse Polish Notation(堆栈)
  3. Ubuntu下VSFTPD(六)(常见FTP命令及其功能) (
  4. MyEclipse中新建html5中文乱码
  5. lintcode : 二叉树的层次遍历II
  6. javascript 命名空间的实例应用
  7. [King.yue]Ext.net 页面布局Flex
  8. EventBus使用小记
  9. Unity之Avatar原理
  10. SQL SERVER中如何格式化日期
  11. Flask 扩展 表单
  12. 关于Python的那些话
  13. GlusterFS 配置及使用
  14. Azure SQL 数据库仓库Data Warehouse (3) DWU
  15. linux 标准I/O (一)
  16. Oracle判断表、列、主键是否存在的方法
  17. 【转】JS实现继承的几种方式
  18. Cocos2d-x CCScale9Sprite 用法
  19. 绕过IE10直接安装VS2013
  20. Python面试题之Super函数

热门文章

  1. Apache ab 测试结果的分析
  2. 提高ubuntu系统性能的小技巧
  3. Feign PathVariable annotation was empty on param 0.
  4. JDK 中的监控与故障处理工具-05 (jstack)
  5. [PyTorch]PyTorch中反卷积的用法
  6. dijkstra算法理解+模板
  7. P3600 随机数生成器
  8. url传递数据类型
  9. python列表解析进阶
  10. BZOJ 1005 [HNOI2008]明明的烦恼 ★(Prufer数列)