gromit / oc-routesbrowser-plugin
该包最新版本(1.1.3)没有可用的许可信息。
OctoberCMS 后端测试路由插件
1.1.3
2023-09-23 16:18 UTC
Requires
README
GromIT.RouteBrowser 是一个 OctoberCMS 插件,帮助后端开发者向前端朋友告知他们在 REST API 中有哪些路由。
它通过反射从代码和 docblocks 收集路由信息。
信息收集来源
每个路由都有 URI、方法、操作、请求类、描述、路由参数和请求参数。
URI、method 和 action 从路由外观中收集,因此您无需在代码中添加任何内容即可在路由列表中显示此信息。
// Here we got route with: uri "hello/{name}", method "GET", action "Closure" // and one route parameter with name "name" type "string" Route::get('hello/{name}', function (string $name) { // });
路由参数 的名称和类型从路由本身收集,但路由描述和参数描述来自路由处理器的 docblock。
docblock 中的路由参数类型覆盖了代码中的类型。
// Docblock for closure adds this info to route: // description "Returns greeting" and route parameter description "Person name" Route::get('hello/{name}', /** * Returns greeting * * @param string $name Person name */ function (string $name) { // } ); // OR // Here route action will be "\Controllers\Namespace\GreetController@greet" Route::get('/hello/{name}', [GreetController::class, 'greet']); class GreetController extends \Illuminate\Routing\Controller { /** * Returns greeting * * @param string $name Person name */ public function greet(string $name) { // } }
请求类 和 请求参数 从用于路由处理器的请求类的 docblock 中收集。
Route::get('/hello/{name}', [GreetController::class, 'greet']); class GreetController extends \Illuminate\Routing\Controller { /** * Returns greeting * * @param string $name Person name */ public function greet(GreetRequest $request, string $name) { // } } // These will add request class "\Requests\Namespace\GreetRequest" and request parameters: // "greeting" with type "string|null" and description "Greeting. Default - "Hello"" // and "friend" with type "string|null" and description "Friend name". /** * @property-read string|null $greeting Greeting. Default - "Hello" * @property-read string|null $friend Friend name */ class GreetRequest extends \Illuminate\Foundation\Http\FormRequest { // }
