一个简单的php路由类
2016-05-29 00:00
302 查看
本文实例为大家分享了php编写一个简单的路由类,供大家参考,具体内容如下
下载地址:https://github.com/cmhc/Hcrail
希望本文所述对大家学习PHP程序设计有所帮助。
php编写一个简单的路由类
PHP URL路由类实例
asp.net不用设置iis实现url重写 类似伪静态路由
thinkphp路由规则使用示例详解和伪静态功能实现(apache重写)
php处理restful请求的路由类分享
php url路由入门实例
thinkphp的URL路由规则与配置实例
ThinkPHP、ZF2、Yaf、Laravel框架路由大比拼
<?php namespace cmhc\Hcrail; class Hcrail { /** * callback function * @var callable */ protected static $callback; /** * match string or match regexp * @var string */ protected static $match; protected static $routeFound = false; /** * deal with get,post,head,put,delete,options,head * @param $method * @param $arguments * @return */ public static function __callstatic($method, $arguments) { self::$match = str_replace("//", "/", dirname($_SERVER['PHP_SELF']) . '/' . $arguments[0]); self::$callback = $arguments[1]; self::dispatch(); return; } /** * processing ordinary route matches * @param string $requestUri * @return */ public static function normalMatch($requestUri) { if (self::$match == $requestUri) { self::$routeFound = true; call_user_func(self::$callback); } return; } /** * processing regular route matches * @param string $requestUri * @return */ public static function regexpMatch($requestUri) { //处理正则表达式 $regexp = self::$match; preg_match("#$regexp#", $requestUri, $matches); if (!empty($matches)) { self::$routeFound = true; call_user_func(self::$callback, $matches); } return; } /** * dispatch route * @return */ public static function dispatch() { if (self::$routeFound) { return ; } $requestUri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $requestMethod = $_SERVER['REQUEST_METHOD']; if (strpos(self::$match, '(') === false) { self::normalMatch($requestUri); } else { self::regexpMatch($requestUri); } } /** * Determining whether the route is found * @return boolean */ public static function isNotFound() { return !self::$routeFound; } }
下载地址:https://github.com/cmhc/Hcrail
希望本文所述对大家学习PHP程序设计有所帮助。
您可能感兴趣的文章:
Phpbean路由转发的php代码php编写一个简单的路由类
PHP URL路由类实例
asp.net不用设置iis实现url重写 类似伪静态路由
thinkphp路由规则使用示例详解和伪静态功能实现(apache重写)
php处理restful请求的路由类分享
php url路由入门实例
thinkphp的URL路由规则与配置实例
ThinkPHP、ZF2、Yaf、Laravel框架路由大比拼
相关文章推荐
- 一个关于if else容易迷惑的问题
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- JSP/PHP基于Ajax的分页功能实现
- 关于PHP通过PDO用中文条件查询MySQL的问题。
- 什么是设计模式
- PHP数据库长连接mysql_pconnect的细节
- Php Installing An Expansion
- rem : web app适配的秘密武器
- php7 读取php.ini[4]
- PHP+Apache在Windows 9x下的安装和配置
- IIS 6 的 PHP 最佳配置方法
- 安装Apache和PHP的一些补充
- Linux Apache+MySQL+PHP
- 建立Apache+PHP+MySQL数据库驱动的动态网站
- PHP 5.3.0 安装分析心得
- apache 环境下 php 的配置注意事项
- 简单好用的PHP分页类
- ASP.NET、ASP、PHP、JSP之间有什么区别?