ciarand / quick-n-dirty-php-router
过渡路由器,帮助升级到现代标准
dev-master
2016-04-11 02:56 UTC
Requires (Dev)
- phpunit/phpunit: ~4.1
This package is not auto-updated.
Last update: 2024-09-24 08:12:21 UTC
README
该项目已弃用且未维护。请谨慎操作!
快速简易PHP路由器
这是一个过渡路由器,帮助将旧PHP代码库升级到更现代的一套标准。
更多详细信息请参考我的博客:重构PHP系列(第一部分)。
用法
在项目中引入它
composer require 'ciarand\quick-n-dirty-router' 'dev-master'
将所有文件移动到handlers目录
# assuming you're in the webroot mkdir ../handlers/ find . -name '*.php' | while read file; do mv "$file" "../handlers/$file"; done;
在Web根目录中的index.php文件中放入以下内容
<?php // index.php require "vendor/autoload.php"; use RestlessCo\Router; // where you keep your scripts (outside of the public web dir) $handler_dir = __DIR__ "/../handler"; // the script you'd like to handle 404s with $missing_script = $handler_dir . "/404.php"; $requested_path = $handler_dir . "/" . Router::scriptForEnv($_SERVER); return require (file_exists($requested_path)) ? $requested_path : $missing_script;
测试
vendor/bin/phpunit
许可证
MIT,完整文本在LICENSE文件中。