1 Star 1 Fork 1

阿债 / pram-web-router

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

\Pram\Web\Router

A lighty web router, inspired by https://github.com/radiosilence/Ham.

一个简便灵活的WEB路由器。

匹配一个网址的控制器只有两次路由:从入口文件中的根路由到达目标文件子路由;包含子路由文件,

从中找到对应的路由项。

避免包含其他不相干路由文件,PHP在文件系统中包含大量代码文件是个耗时操作,Drupal的boot过程就是一个例子。

PHP的特点是访问一次释放所有资源,并不适合常见的集中管理全部URL,分段映射的方式。

使用方法

    <?php
    require_once __DIR__ . '/pram3/src/boot.php';
    require_once __DIR__ . '/pram3/src/Pram/Web/Router.php';
    //创建根路由,同时会作为当前路由
    $root = new \Pram\Web\Router(); //根路由
    //指定扫描子路由器规则,当前文件不需要扫描
    $root->glob(__DIR__, '*.php');
    $root->glob(__DIR__, '*' . DIRECTORY_SEPARATOR . '*.php');
    
    //创建一些路由项到当前路由器,控制器是一个Closure
    route('/', function(){ return __FILE__ . ':' . __LINIE__; });
    //故意添加两个空过滤器
    route('/a/b/c/', function(){ return __FILE__ . ':' . __LINIE__; }, null, null);

没有找到匹配项时,返回空数组,否则返回数组中含有以下元素

  • handler mixed 控制器
  • filters array 过滤器数组
  • url string 网址
  • args array 占位符对应值数组
The MIT License (MIT) Copyright (c) 2013 Ryan Liu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个简便灵活的WEB路由器。 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/azhai/pram-web-router.git
git@gitee.com:azhai/pram-web-router.git
azhai
pram-web-router
pram-web-router
master

搜索帮助