eylmz/router
Composer 安装命令:
composer require eylmz/router
包简介
Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
README 文档
README
Router - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.
Version : 1.0.0
- Installation
- Simple Usage
- Available Router Methods
- Route Parameters
- Controller and Method Parameters
- Regular Expression Constraints
- Named Routes
- Route Groups
- License
Installation
You can download it and using it without any changes.
OR use Composer.
It's recommended that you use Composer to install Route.
$ composer require eylmz/router
Simple Usage
.htaccess
Options -Indexes
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
index.php
<?php require 'vendor/autoload.php'; // or // require 'src/eylmz/Router.php'; use eylmz/Router/Router; Router::setControllerNamespace("App\\Controllers\\"); Router::setMiddlewareNamespace("App\\Middlewares\\"); // Routers Router::any("/url","Controller@Method"); // or Router::any("/url2",function() { }); // #Routers Router::routeNow(@$_GET["url"]);
Available Router Methods
Router::get($url, $callback); Router::post($url, $callback); Router::put($url, $callback); Router::patch($url, $callback); Router::delete($url, $callback); Router::options($url, $callback);
Usage More Than One Routers
Router::match("GET|POST",$url,$callback); //or Router::match(["GET","POST"],$url,$callback);
Usage The Any Methods
Router::any($url,$callback);
Route Parameters
Required Parameters
Router::get("url\{id}",function($myID){ echo "Hello " . $myID; });
Optional Parameters
Router::get("url\{id?}",function($myID=0){ echo $myID; });
Controller and Method Parameters
// Controller -> First Parameter // Method -> Second Parameter Router::get("admin\{controller}\{method}","{?}@{?}"); // or // Custom Router::get("admin\{method}\{controller}","{controller}@{method}");
Regular Expression Constraints
Router::get('url/{id}', function ($myID) { })->where('id', '[0-9]+'); Router::get('user/{id}/{name}', function ($myID, $name) { })->where(['id' => '[0-9]+', 'name' => '[a-zA-Z]+']);
Named Routes
Router::get('user/profile', function () { // })->name('profile');
Generating URLs To Named Routes
$url = Router::route("profile"); // Usage with parameters Router::get('url/{id}/profile', function ($id) { })->name('profile'); $url = Router::route('profile', ['id' => 1]);
Route Groups
Prefix URL
Router::prefix('admin')->group(function () { Router::get('users', function () { // new url -> /admin/users }); });
Middleware
Router::middleware("middleware")->group(function () { Router::get('/', function () { }); Router::get('url/profile', function () { }); });
Usage More Than One Middlewares
Router::middleware(["middleware","middleware2"])->group(function () { Router::get('/', function () { }); Router::get('url/profile', function () { }); });
License
The MIT License (MIT). Please see License File for more information.
eylmz/router 适用场景与选型建议
eylmz/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47 次下载、GitHub Stars 达 15, 最近一次更新时间为 2017 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「restful」 「mvc」 「router」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eylmz/router 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eylmz/router 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eylmz/router 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
This is a restful api to onesignal.
A RESTful API package for the Laravel and Lumen frameworks.
Alfabank REST API integration
Simple and lightweight HTTP client based cURL
RESTful API server for structured and self-documenting resources over JSON, XML, ...
统计信息
- 总下载量: 47
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-18