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