国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

一個簡單的php路由類

2024-05-04 23:46:52
字體:
來源:轉載
供稿:網友
這篇文章主要為大家詳細介紹了一個簡單的php路由類,感興趣的小伙伴們可以參考一下
 

本文實例為大家分享了php編寫一個簡單的路由類,供大家參考,具體內容如下

<?phpnamespace 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程序設計有所幫助。



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 宣城市| 南木林县| 阿拉善盟| 巴南区| 肥城市| 安仁县| 曲水县| 宜城市| 巢湖市| 林甸县| 新宾| 孝义市| 南江县| 霍林郭勒市| 扎鲁特旗| 钟祥市| 灵台县| 伊宁县| 泰和县| 库伦旗| 突泉县| 贵溪市| 开封市| 垣曲县| 松原市| 城市| 鹤山市| 布尔津县| 高清| 芜湖市| 曲松县| 拜城县| 玛沁县| 元氏县| 大理市| 昌乐县| 南投市| 滁州市| 河西区| 凌海市| 潜江市|