Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<?php
declare(strict_types=1);
namespace Tests\Router;
/**
* @api(
* title="Summary",
* zh-CN:title="姒傝堪",
* zh-TW:title="姒傝堪",
* path="router/README",
* description="
* 瀵逛簬涓涓鏋舵潵璇磋矾鐢辨槸涓浠堕潪甯搁噸瑕佺殑浜嬫儏锛屽彲浠ヨ鏄鏋剁殑鏍稿績涔嬩竴銆傝矾鐢辩殑浣跨敤渚挎嵎鍜岀悊瑙e鏉傚害浠ュ強鎬ц兘瀵规暣涓鏋舵潵璇磋嚦鍏抽噸瑕併
* ",
* zh-CN:description="
* 瀵逛簬涓涓鏋舵潵璇磋矾鐢辨槸涓浠堕潪甯搁噸瑕佺殑浜嬫儏锛屽彲浠ヨ鏄鏋剁殑鏍稿績涔嬩竴銆傝矾鐢辩殑浣跨敤渚挎嵎鍜岀悊瑙e鏉傚害浠ュ強鎬ц兘瀵规暣涓鏋舵潵璇磋嚦鍏抽噸瑕併
* ",
* zh-TW:description="
* 瀵逛簬涓涓鏋舵潵璇磋矾鐢辨槸涓浠堕潪甯搁噸瑕佺殑浜嬫儏锛屽彲浠ヨ鏄鏋剁殑鏍稿績涔嬩竴銆傝矾鐢辩殑浣跨敤渚挎嵎鍜岀悊瑙e鏉傚害浠ュ強鎬ц兘瀵规暣涓鏋舵潵璇磋嚦鍏抽噸瑕併
* ",
* )
*/
class SummaryDoc
{
/**
* @api(
* zh-CN:title="璺敱瑙f瀽",
* zh-CN:description="
* QueryPHP 鏈変竴涓潪甯哥嫭鐗圭殑鍦版柟灏辨槸璺敱璁捐涓庡叾瀹冩鏋舵湁鐐瑰嚭鍏ワ紝鎴戜滑涓嶉渶瑕佸儚 Laravel 5銆乀hinkphp 5 绛夋鏋朵竴鏍峰畾涔夎矾鐢便
*
* ### Laravel 5
*
* ``` php
* Route::middleware(['first', 'second'])->group(function () {
* Route::get('/', function () {
* });
* Route::get('user/profile', function () {
* });
* });
* ```
*
* ### ThinkPHP 5
*
* ``` php
* Route::group('blog', function () {
* Route::rule(':id', 'blog/read');
* Route::rule(':name', 'blog/read');
* })->ext('html')->pattern(['id' => '\d+', 'name' => '\w+']);
* ```
*
* ### FastRoute
*
* ``` php
* $r->addRoute('GET', '/user/{id:\d+}', 'handler');
* $r->addRoute('GET', '/user/{name}', 'handler');
* $r->addRoute('GET', '/user/{name:.+}', 'handler');
* ```
*
* ::: tip
* 鍏朵腑 FastRoute 涓彁渚涗竴涓矾鐢 10 鏉¤矾鐢卞悎骞跺尮閰嶇畻娉曢潪甯稿湴楂樻晥锛孮ueryPHP 宸茬粡鍚告敹銆 [鍚堝苟璺敱鍖归厤绠楁硶](http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-expressions.html)
* :::
*
* ### PHP 8 娉ㄨВ璺敱
*
* QueryPHP 寮濮嬮噰鐢 PHP 8 灞炴ф潵瀹氫箟娉ㄨВ璺敱锛屽彲浠ュ緢杞绘澗鍦板疄鐜版瘮杈冨鏉傜殑璺敱璁块棶銆
*
* QueryPHP 妗嗘灦鎻愪緵 `MVC 鑷姩璺敱` 骞惰兘澶熸櫤鑳借В鏋 Restful 璇锋眰鍜屽熀浜 PHP 8 灞炴х殑娉ㄨВ璺敱銆
* 鎵浠ユ垜浠笉闇瑕佸畾涔変竴涓 router.php 鏉ユ敞鍐屾垜浠殑璺敱锛屽苟涓旇兘澶熶紭鍖栧苟缂撳瓨璧锋潵鍔犻熻В鏋愩
* ",
* zh-CN:note="",
* lang="",
* )
*/
public function doc1(): void
{
}
/**
* @api(
* zh-CN:title="璺敱鍖归厤杩囩▼",
* zh-CN:description="
* QueryPHP 浼氫紭鍏堣繘琛宍MVC 鑷姩璺敱`鍖归厤锛屼篃鍖呭惈 `Restful` 璺敱鍖归厤,濡傛灉鍖归厤澶辫触灏变細杩涜娉ㄨВ璺敱鍖归厤闃舵锛屽鏋滆繕鏄
* 鍖归厤澶辫触鍒欎細鎶涘嚭涓涓矾鐢辨棤娉曟壘鍒扮殑寮傚父銆
* ",
* zh-CN:note="",
* lang="",
* )
*/
public function doc2(): void
{
}
/**
* @api(
* zh-CN:title="鑷姩 MVC 璺敱",
* zh-CN:description="
* 寰堝鏃跺欐垜浠笉鏄壒鍒叧蹇冨畠鏄 GET銆丳OST 杩樻槸 PUT锛屾垜浠氨鎯崇畝鍗曡緭鍏ヤ竴涓湴鍧灏卞彲浠ヨ闂埌鎴戜滑鐨勬帶鍒跺櫒銆
*
* 璺緞 | 鍖归厤鎺у埗鍣 | 澶囨敞
* --|---|--
* / | App\App\Controller\Home::index() |
* /controller/action | App\App\Controller\Controller::action() |
* /:blog/controller/action | Blog\App\Controller\Controller::action() | `:` 琛ㄧず搴旂敤
* /dir1/dir2/dir3/controller/action | App\App\Controller\Dir1\Dir2\Dir3\Controller::action() |
* /he_llo-wor/Bar/foo/xYY-ac/controller_xx-yy/action-xxx_Yzs | App\App\Controller\HeLloWor\Bar\Foo\XYYAc\ControllerXxYy::actionXxxYzs() |
*
* ::: warning
* 濡傛灉鏂规硶鍗曠嫭鎴愪负涓涓被锛屽垯瀵瑰簲鐨勮姹傚叆鍙d负 `handle`锛屾垜浠帹鑽愪负姣忎竴涓柟娉曞畾涔変竴涓被锛岄伩鍏嶄笌鍏跺畠鏂规硶鍐茬獊锛岃屼笖璺敱鍖归厤鎬ц兘鏈浣炽
* 妗嗘灦搴曞眰浼氫紭鍏堝尮閰嶆柟娉曞崟鐙垚绫伙紝鍖归厤澶辫触鍒欏尮閰嶆帶鍒跺櫒绫诲搴旀柟娉曟搷浣滐紝濡傛灉杩樻槸鍖归厤澶辫触杩涘叆娉ㄨВ璺敱鍖归厤闃舵銆
* :::
*
* 渚嬪璁块棶鍦板潃 `http://queryphp.cn/api/test`:
*
* ",
* note="涓婇潰杩欑灏辨槸涓涓畝鍗曠矖鏆寸殑璺敱锛岀畝鍗曟湁鏁堬紝澶у鏁版椂鍊欏彲浠ユ弧瓒虫垜浠郴缁熷紑鍙戠殑闇姹傘",
* lang="php",
* )
*/
public function doc3(): void
{
<<<'EOT'
<?php
declare(strict_types=1);
namespace App\App\Controller\Api;
/**
* api tests.
*/
class Test
{
/**
* 榛樿鏂规硶.
*/
public function handle(): array
{
return ['hello' => 'world'];
}
}
EOT;
}
/**
* @api(
* zh-CN:title="鑷姩 restful 璺敱",
* zh-CN:description="
* Restful 宸茬粡鏄竴绉嶅紑鍙戜富娴侊紝鍓嶅悗绔垎绂荤殑鍦烘櫙鎴戜滑閫氬父浼氬畾涔 Restful 璺敱鏉ュ悜鍓嶇鎻愪緵鎺ュ彛鏈嶅姟銆
*
* 鎴戜滑璁块棶鍚屼竴涓 URL 鐨勬椂鍊,鏍规嵁涓嶅悓鐨刞璇锋眰绫诲瀷`璁块棶涓嶅悓鐨勫悗鍙般
*
* 璺緞 | 璇锋眰绫诲瀷 | 鍖归厤鎺у埗鍣 | 澶囨敞
* -- | --- | --- |--
* /car | GET | App\App\Controller\Car::index() | 娌℃湁鍙傛暟鍒欒姹傚垪琛
* /car/5 | GET | App\App\Controller\Car::show() |
* /car/5 | POST | App\App\Controller\Car::store() |
* /car/5 | DELETE | App\App\Controller\Car::destroy() |
* /car/5 | PUT | App\App\Controller\Car::update() |
* /car/5/otherGet | GET | App\App\Controller\Car::otherGet() |
* /car/5/otherPost | POST | App\App\Controller\Car::otherPost() |
*
* 璺敱绯荤粺浼氬垎鏋 pathInfo锛岀郴缁熶細棣栧厛灏濊瘯姝e垯鍖归厤 Restful 椋庢牸锛屽惁鍒欐墽琛屼紶缁 `MVC` 鍖归厤銆
*
* Restful 椋庢牸璺敱濡傛灉鍖归厤鎴愬姛锛屽鏋滆繖涓椂鍊欐病鏈夋柟娉曪紝绯荤粺鏍规嵁璇锋眰绫诲瀷鑷姩琛ュ叏鏂规硶瀹屾垚 Restful 璇锋眰.
*
* 鎴戜滑鍙互閫氳繃 Request 涓殑 attributes 鏉ヨ闂弬鏁颁腑鐨 Restful 璧勬簮 ID銆
*
* ``` php
* (int) \Leevel::make('request')->attributes->get(\Leevel\Router\IRouter::RESTFUL_ID);
* ```
* ",
* note="",
* )
*/
public function doc4(): void
{
}
/**
* @api(
* zh-CN:title="PHP 8 娉ㄨВ璺敱",
* zh-CN:description="
* 涓婇潰鏄竴绉嶉鐑紝鎴戜滑鐨勬鏋惰矾鐢辫璁℃槸杩欐牱锛屼紭鍏堣繘琛 `pathInfo` 瑙f瀽锛屽鏋滆В鏋愬け璐ュ皢杩涘叆娉ㄨВ璺敱楂樼骇瑙f瀽闃舵銆
*
* ### 鍩虹
*
* 璺緞 | 鍖归厤鎺у埗鍣 | 澶囨敞
* --|---|--
* http://127.0.0.1:9527/api/v1/demo/liu | 璺敱 | 娉ㄨВ璺敱
*
* 璁块棶 `http://127.0.0.1:9527/api/v1/demo/liu`:
*
* ```
* Hi you, you name is liu in version 1
* ```
*
* QueryPHP 閲囩敤 PHP 8 灞炴ф潵瀹氫箟娉ㄨВ璺敱锛岄渶瑕佸畾涔 `Route` 娉ㄨВ璺敱銆傘
* ",
* note="",
* )
*/
public function doc5(): void
{
<<<'EOT'
#[Route(
path: "/api/v1/demo/{name:[A-Za-z]+}/",
attributes: ["args1" => "hello", "args2" => "world"],
)]
public function demo1(string $name): string
{
return sprintf('Hi you, you name is %s in version 1', $name);
}
EOT;
}
/**
* @api(
* zh-CN:title="",
* zh-CN:description="
* VS Laravel:
*
* ``` php
* Route::get('/', function () {
* });
* ```
*
* ### 鍗曟潯璺敱
*
* 绯荤粺鏀寔涓浜涜嚜瀹氫箟灞炴э紝鍙互鎵╁睍鐪嬭矾鐢辩殑鍔熻兘銆
*
* ```
* attributes: ["args1" => "hello", "args2" => "world"],
* bind: "\\App\\App\\Controller\\Petstore\\Pet@withBind",
* domain: "{subdomain:[A-Za-z]+}-vip.{domain}",
* middlewares: "api",
* port: "9527",
* scheme: "https",
* ```
*
* ::: tip
* * 鍙傛暟 bind 鏈缃紝绯荤粺浼氳嚜鍔ㄧ粦瀹氬綋鍓嶆敞閲婄殑鎺у埗鍣ㄦ柟娉
* * 鍙傛暟 bind 榛樿浼氱粦瀹氬埌绫荤殑 `handle` 鏂规硶锛宍@` 鍙互鍒欏彲浠ヨ嚜瀹氫箟缁戝畾鏂规硶
* :::
*
* 璺敱鍦板潃 path 鍜屽煙鍚嶆敮鎸佹鍒欏弬鏁
*
* ```
* /api/v1/petLeevelForApi/{petId:[A-Za-z]+}/
* {subdomain:[A-Za-z]+}-vip.{domain}
* ```
* ",
* note="",
* )
*/
public function doc6(): void
{
}
/**
* @api(
* zh-CN:title="缁撴潫璇",
* zh-CN:description="
* 璺敱鍩烘湰浠嬬粛瀹屼簡锛屼富瑕佺敱涓ょ椋庢牸鐨勮矾鐢辨瀯鎴愩
* ",
* note="",
* )
*/
public function doc7(): void
{
}
}