本文实例为大家分享了php编写一个简单的路由类,供大家参考,具体内容如下
<"//", "/", 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程序设计有所帮助。
标签:
php,路由类
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“一个简单的php路由类”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。