Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time

PhpBoot

PhpBoot 鏄负蹇熷紑鍙 寰湇鍔 / RESTful API 璁捐鐨凱HP妗嗘灦銆傚畠鍙互甯姪寮鍙戣呮洿鑱氱劍鍦ㄤ笟鍔℃湰韬, 鑰屽皢鍘熸潵寮鍙戜腑涓嶅緱涓嶅仛, 浣嗗張閲嶅鏋嚗鐨勪簨鎯呬涪缁欐鏋, 姣斿缂栧啓鎺ュ彛鏂囨。銆佸弬鏁版牎楠屽拰杩滅▼璋冪敤浠g爜绛夈

鐗硅壊

PhpBoot 妗嗘灦鎻愪緵璁稿涓绘祦鐨勭壒鎬, 濡侷OC銆丠OOK銆丱RM绛夈 杩欎簺鐗规ч兘缁忚繃绮惧績璁捐鍜岄夋嫨(鏈変簺鏄涓夋柟寮婧愪唬鐮,濡 PHP-DI)锛屼絾鍜屽叾浠栨鏋剁浉姣旇緝, PhpBoot 鏈鏄捐憲鐨勭壒鑹叉槸:

1. 浠ラ潰鍚戝璞$殑鏂瑰紡缂栧啓鎺ュ彛

浣犺偗瀹氱湅鍒拌繃杩欐牱鐨勪唬鐮:

// **涓嶇敤** PhpBoot 鐨勪唬鐮
class BookController
{
    public function findBooks(Request $request)
    {
        $name = $request->get('name');
        $offset = $request->get('offset', 0);
        $limit = $request->get('limit', 10);
        ...
        return new Response(['total'=>$total, 'data'=>$books]);
    }

public function createBook(Request $request)
    ...
}

寰堝涓绘祦妗嗘灦閮介渶瑕佺敤绫讳技浠g爜缂栧啓鎺ュ彛銆備絾杩欑浠g爜鐨勪竴涓棶棰樻槸, 鏂规硶鐨勮緭鍏ヨ緭鍑洪殣钘忓湪瀹炵幇閲, 杩欎笉鏄氬父鎴戜滑鎻愬$殑缂栫爜鏂瑰紡銆傚鏋滀綘瀵逛唬鐮佽姹傛洿楂, 浣犲彲鑳借繕浼氬疄鐜颁竴灞 Service 鎺ュ彛, 鑰屽湪 Controller 閲屽彧鏄畝鍗曠殑鍘昏皟鐢 Service 鎺ュ彛銆傝屼娇鐢 PhpBoot, 浣犲彲浠ョ敤鏇磋嚜鐒剁殑鏂瑰紡鍘诲畾涔夊拰瀹炵幇鎺ュ彛銆備笂闈㈢殑渚嬪瓙, 鍦 PhpBoot 妗嗘灦涓疄鐜版槸杩欐牱鐨:

/**
 * @path /books/
 */
class Books
{
    /**
     * @route GET /
     * @return Book[]
     */
    public function findBooks($name, &$total=null, $offset=0, $limit=10)
    {
        $total = ...
        ...
        return $books;
    }

    /**
     * @route POST /
     * @param Book $book {@bind request.request} bind $book with http body
     * @return string id of created book
     */
    public function createBook(Book $book)
    {
        $id = ...
        return $id;
    }
}

涓婇潰涓や唤浠g爜鎵ц鐨勬晥鏋滄槸涓鏍风殑銆傚彲浠ョ湅鍒 PhpBoot 缂栧啓鐨勪唬鐮佹洿绗﹀悎闈㈠悜瀵硅薄缂栫▼鐨勫師鍒, 浠ヤ笂浠g爜瀹屾暣鐗堟湰璇疯 phpboot-example

2. 杞绘澗鏀寔 Swagger

Swagger 鏄洰鍓嶆渶娴佽鐨勬帴鍙f枃妗f鏋躲傝櫧鐒跺緢澶氭鏋堕兘鍙互閫氳繃鎵╁睍鏀寔Swagger, 浣嗕竴鑸笉鏄渶瑕佺紪鍐欏緢澶氶澶栫殑娉ㄩ噴, 灏辨槸鍙兘瀵煎嚭鍩烘湰鐨勮矾鐢变俊鎭, 鑰屼笉鑳藉鍑鸿缁嗙殑杈撳叆杈撳嚭鍙傛暟銆傝 PhpBoot 鍙互鍦ㄤ笉澧炲姞棰濆缂栫爜璐熸媴鐨勬儏鍐典笅, 杞绘澗鍘诲畬鎴愪笂杩颁换鍔★紝涓嬪浘涓篺indBooks瀵瑰簲鐨勬枃妗c傛洿澶氬唴瀹硅瑙 鏂囨。鍦ㄧ嚎 Demo

https://github.com/caoym/phpboot/raw/master/docs/_static/WX20170809-184015.png

3. 绠鍗曟槗鐢ㄧ殑鍒嗗竷寮忔敮鎸

浣跨敤 PhpBoot 鍙互寰堢畝鍗曠殑鏋勫缓鍒嗗竷寮忓簲鐢ㄣ傞氳繃濡備笅浠g爜, 鍗冲彲杞绘澗杩滅▼璁块棶涓婇潰绀轰緥涓殑 Books 鎺ュ彛:

$books = $app->make(RpcProxy::class, [
        'interface'=>Books::class,
        'prefix'=>'http://x.x.x.x/'
    ]);

$books->findBooks(...);

鍚屾椂杩樺彲浠ユ柟渚跨殑鍙戣捣骞跺彂璇锋眰, 濡:

$res = MultiRpc::run([
    function()use($service1){
        return $service1->doSomething();
    },
    function()use($service2){
        return $service2->doSomething();
    },
]);

鏇村鍐呭璇锋煡鐪 鏂囨。

4. IDE 鍙嬪ソ

IDE 鐨勪唬鐮佹彁绀哄姛鑳藉彲浠ヨ寮鍙戣呰交鏉句笉灏, 浣嗗緢澶氭鏋跺湪杩欐柟闈㈠仛鐨勫苟涓嶅ソ, 浣犲繀椤荤湅鏂囨。鎴栬呬唬鐮, 鎵嶈兘鐭ラ亾鏌愪釜鍔熻兘鐨勭敤娉曘侾hpBoot 鍦ㄤ竴寮濮嬪氨闈炲父娉ㄩ噸妗嗘灦鐨 IDE 鍙嬪ソ鎬, 灏藉彲鑳借妗嗘灦淇濇寔鍑嗙‘鐨勪唬鐮佹彁绀恒傛瘮濡備笅鍥炬槸 DB 搴撳湪 PhpStorm 涓嬬殑浣跨敤:

https://github.com/caoym/phpboot/raw/master/docs/_static/db.gif

鍙互鐪嬪埌, IDE 鐨勬彁绀烘槸绗﹀悎 SQL 璇硶瑙勫垯鐨, 骞朵笉鏄畝鍗曠綏鍒楁墍鏈 SQL 鎸囦护銆

甯姪

  • QQ 浜ゆ祦缇:185193529
  • 鏈汉閭 caoyangmin@gmail.com

鏂囨。

.. toctree::
    :maxdepth: 1
    :caption: 蹇熷紑濮

    quick-start/install.md
    quick-start/requirements.md
    quick-start/webserver-config.md
    quick-start/example.md

.. toctree::
    :maxdepth: 1
    :caption: 鍩虹鐗规

    basic/annotation
    basic/route.md
    basic/params-bind.md
    basic/validation.md
    basic/di.md
    basic/db.md
    basic/cache.md

.. toctree::
    :maxdepth: 1
    :caption: 楂樼骇鐗规

    advanced/docgen.md
    advanced/orm.md
    advanced/hook.md
    advanced/rpc.md
    advanced/cli.md

.. toctree::
    :maxdepth: 1
    :caption: FAQ

    faq.md