eightyfive/laravel-autoroute
最新稳定版本:v3.0.0-alpha.20
Composer 安装命令:
composer require eightyfive/laravel-autoroute
包简介
Laravel YAML routes
README 文档
README
Autoroute helps you register Laravel routes as YAML.
"La route? Là où on va, on a pas besoin... De route."
Install
composer require eyf/laravel-autoroute
Usage
<?php // app/Providers/RouteServiceProvider.php use Eyf\Autoroute\Autoroute; class RouteServiceProvider extends ServiceProvider { public function map(Autoroute $autoroute) { $autoroute->load(["api.yaml"]); } }
Note: It will automatically look for files inside the Laravel routes/ folder.
Sample api.yaml
domain: api.example.org prefix: v1 middleware: - api namespace: App\Http\Controllers\Api paths: "users": get: uses: UserController@index post: uses: UserController@store "users/{id}": get: uses: UserController@find put: uses: UserController@update
Or using the compact syntax:
domain: api.example.org prefix: v1 middleware: - api namespace: App\Http\Controllers\Api paths: "users": get: user.index post: user.store "users/{id}": get: user.find put: user.update
Template parameters
Autoroute supports light parameters in YAML files. The format is %<parameter_name>%.
For instance let's say you need to work with a local API subdomain:
<?php // app/Providers/RouteServiceProvider.php use Eyf\Autoroute\Autoroute; class RouteServiceProvider extends ServiceProvider { public function map(Autoroute $autoroute) { $parameters = [ "app_domain" => env("APP_DOMAIN", "example.org"), ]; $autoroute->load(["api.yaml"], $parameters); } }
And in your local .env file:
APP_DOMAIN=localhost:8000 # APP_DOMAIN=example.org # PROD
And in your api.yaml file:
domain: api.%app_domain% prefix: v1 # ...
Default route names
If you don't provide an as option in your route definition:
"users/{id}": get: uses: UserController@find as: my_user_find_route_name
Autoroute will generate a default route name based on the current namespace, controller and action names:
"users/{id}": get: uses: UserController@find # as: api.user.find (generated)
Custom default route name
If you're not happy with the default route name format, you can implement your own Eyf\Autoroute\RouteNamerInterface and bind it accordingly in your Laravel app service provider:
<?php // app/Providers/AppServiceProvider.php use Eyf\Autoroute\RouteNamerInterface; use App\Services\MyRouteNamer; class AppServiceProvider extends ServiceProvider { public function register() { $this->app->bind(RouteNamerInterface::class, MyRouteNamer::class); } }
uses compact syntax
If you're not using any route options (as, etc...), you can use a "compact" syntax to specify your controllers:
domain: api.%app_domain% prefix: v1 middleware: - api namespace: App\Http\Controllers\Api paths: "users": get: user.index post: user.store "users/{id}": get: user.find put: user.update
Custom compact syntax
You can customize the shorthand syntax by implementing RouteNamerInterface::getUses(string $compact).
eightyfive/laravel-autoroute 适用场景与选型建议
eightyfive/laravel-autoroute 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.02k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 01 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「routing」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 eightyfive/laravel-autoroute 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 eightyfive/laravel-autoroute 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 eightyfive/laravel-autoroute 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Write down your routing mapping at one place
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
SUML for PHP
SUML support for Symfony
provides an facade for php-yaml, syck and symphony/yaml so switching in between is easier
Especificação do formato Cnab240 e Cnab400 traduzida para Yaml
统计信息
- 总下载量: 6.02k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-29