<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          PhalApi輕量級PHP開源接口框架

          聯(lián)合創(chuàng)作 · 2023-09-20 11:06

          PhalApi接口框架 / PhalApi API Framework

          PhalApi Pro 專業(yè)版 - 專注接口開發(fā)管理和開放平臺搭建
          PhalApi Pro - focus on API and Open Platform

          開發(fā)文檔 / Documents

          專為PHPer準(zhǔn)備的優(yōu)雅而詳細(xì)的開發(fā)文檔,請看:PhalApi 2.x 開發(fā)文檔
          PhalApi 2.x English Docs.

          在線示例 / Demo

          快速安裝 / Install

          composer一鍵安裝 / Install by composer

          使用composer創(chuàng)建項(xiàng)目的命令,可實(shí)現(xiàn)一鍵安裝。

          One-click installation can be achieved by using the command of composer to create a project.

          $ composer create-project phalapi/phalapi

          溫馨提示:關(guān)于composer的使用,請參考Composer 中文網(wǎng) / Packagist 中國全量鏡像。

          手動下載安裝 / Download and Install manually

          或者,也可以進(jìn)行手動安裝。將此Git項(xiàng)目代碼下載解壓后,進(jìn)行可選的composer更新,即:
          Alternatively, manual installation is also possible. Download PhalApi Project master-2x branch Source code. After downloading and unzipping, perform an optional composer update:

          $ composer update

          部署 / Deployment

          Nginx配置 / Nginx Configuration

          如果使用的是Nginx,可參考以下配置。
          If you are using Nginx, you can refer to the following configuration.

          server {
              listen 80;
              server_name dev.phalapi.net;
              # 將根目錄設(shè)置到public目錄
              root /path/to/phalapi/public;
              charset utf-8;
          
              location / {
                  index index.php;
              }
          
              location ~ \.php$ {
                  fastcgi_split_path_info ^(.+\.php)(/.+)$;
                  # 根據(jù)當(dāng)前環(huán)境,選擇合適的通訊方式
                  # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  include fastcgi_params;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              }
          }

          配置時(shí)需要將網(wǎng)站根目錄設(shè)置到public目錄,配置保存后重啟nginx。
          Point the root path of the visit to public folder. Save and reload nginx.

          溫馨提示:推薦將訪問根路徑指向/path/to/phalapi/public。
          Tips: It is recommended to point the root path of the visit to /path/to/phalapi/public.

          數(shù)據(jù)庫配置 / Database Configuration

          如何使用的是MySQL數(shù)據(jù)庫,參考修改./config/dbs.php數(shù)據(jù)庫配置。
          If you are using MySQL, please edit ./config/dbs.php.

          return array(
              /**
               * DB數(shù)據(jù)庫服務(wù)器集群 / database cluster
               */
              'servers' => array(
                  'db_master' => array(                       // 服務(wù)器標(biāo)記 / database identify
                      'type'      => 'mysql',                 // 數(shù)據(jù)庫類型,暫時(shí)只支持:mysql, sqlserver / database type
                      'host'      => '127.0.0.1',             // 數(shù)據(jù)庫域名 / database host
                      'name'      => 'phalapi',               // 數(shù)據(jù)庫名字 / database name
                      'user'      => 'root',                  // 數(shù)據(jù)庫用戶名 / database user
                      'password'  => '',	                    // 數(shù)據(jù)庫密碼 / database password
                      'port'      => 3306,                    // 數(shù)據(jù)庫端口 / database port
                      'charset'   => 'UTF8',                  // 數(shù)據(jù)庫字符集 / database charset
                      'pdo_attr_string'   => false,           // 數(shù)據(jù)庫查詢結(jié)果統(tǒng)一使用字符串,true是,false否
                      'driver_options' => array(              // PDO初始化時(shí)的連接選項(xiàng)配置
                          // 若需要更多配置,請參考官方文檔:https://www.php.net/manual/zh/pdo.constants.php
                      ),
                  ),
              ),
          
              // 更多代碼省略……
          );

          最后,需要給runtime目錄添加寫入權(quán)限。更多安裝說明請參考文檔下載與安裝。
          At last, add writeable permission to folder runtime. For more detail about installation, refer to Download and Installation.

          使用 / Usage

          調(diào)用接口 / API Request

          在PhalApi,你可以通過service參數(shù)(短名字是s參數(shù))指定需要調(diào)用的接口服務(wù)。例如,訪問默認(rèn)接口服務(wù)。

          For PhalApi, the default communicate protocol is HTTP/HTTPS. According to the specific implementation of the API service, we could use GET or POST to request. By default, you can specify the service parameter or s for short when requesting. The default API service is App.Site.Index.

          對應(yīng)執(zhí)行的PHP代碼在./src/app/Api/Site.php文件,源碼片段如下:
          The source PHP code of App.Site.Index API service is at ./src/app/Api/Site.php file.

          <?php
          namespace App\Api;
          use PhalApi\Api;
          
          /**
           * 默認(rèn)接口服務(wù)類
           * @author: dogstar <[email protected]> 2014-10-04
           */
          class Site extends Api {
              public function getRules() {
                  return array(
                      'index' => array(
                          'username'  => array('name' => 'username', 'default' => 'PhalApi', 'desc' => '用戶名'),
                      ),
                  );
              }
          
              /**
               * 默認(rèn)接口服務(wù)
               * @desc 默認(rèn)接口服務(wù),當(dāng)未指定接口服務(wù)時(shí)執(zhí)行此接口服務(wù)
               * @return string title 標(biāo)題
               * @return string content 內(nèi)容
               * @return string version 版本,格式:X.X.X
               * @return int time 當(dāng)前時(shí)間戳
               * @exception 400 非法請求,參數(shù)傳遞錯(cuò)誤
               */
              public function index() {
                  return array(
                      'title' => 'Hello ' . $this->username,
                      'version' => PHALAPI_VERSION,
                      'time' => $_SERVER['REQUEST_TIME'],
                  );
              }
          }

          接口請求后結(jié)果輸出類似如下:
          API result as below after requesting:

          {
              "ret": 200,
              "data": {
                  "title": "Hello PhalApi",
                  "version": "2.4.2",
                  "time": 1501079142
              },
              "msg": ""
          }

          運(yùn)行效果,截圖如下:
          Runtime Sreenshot:

          _20190201151943

          查看在線接口文檔 / Visit Online API List Documents

          PhalApi會根據(jù)你編寫的接口的參數(shù)配置和代碼注釋,自動實(shí)時(shí)生成在線接口文檔。在線接口文檔鏈接為:
          PhalApi will generate realtime online API documents automatically by PHP code and PHP comments. You can visit them by:

          瀏覽效果類似如下:
          Preview:

          進(jìn)入Portal運(yùn)營平臺 / Use Portal Platform

          PhalApi采用了當(dāng)前流行且優(yōu)秀的layuimin開發(fā)全新的管理后臺,專門提供給非技術(shù)的運(yùn)營人員使用(技術(shù)人員也可使用)。安裝Portal前請先配置好數(shù)據(jù)庫連接。如果需要單獨(dú)升級Portal,可進(jìn)入應(yīng)用市場免費(fèi)下載到本地后安裝升級。

          PhalApi provides a new management system and we name it Portal.

          翻譯 / i18n

          修改./public/init.php文件,可設(shè)置當(dāng)前語言。
          Edit ./public/init.php file to set current language.

          // 翻譯語言包設(shè)定-簡體中文
          \PhalApi\SL('zh_cn');
          
          // Setting language to English
          \PhalApi\SL('en');

          一張圖告訴你如何使用PhalApi 2.x / All in One Picture

          phalapi-install

          子項(xiàng)目 / Sub Projects

          還有問題,怎么辦?/ Any Question?

          如發(fā)現(xiàn)問題,或者任何問題,歡迎提交Issue到這里,或進(jìn)入PhalApi開源社區(qū)。
          如果喜歡,請幫忙在Github碼云給個(gè)Star,也可以對PhalApi進(jìn)行捐贈哦 ^_^。

          Welcome to report any issue here.
          If you like PhalApi, welcome to give us a Star at Github.

          開源許可協(xié)議 / Licence

          Apache 2.0,Apache Licence是著名的非盈利開源組織Apache采用的協(xié)議。該協(xié)議和BSD類似,同樣鼓勵(lì)代碼共享和尊重原作者的著作權(quán),同樣允許代碼修改,再發(fā)布(作為開源或商業(yè)軟件)。

          瀏覽 26
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  大香蕉伊人影院网站 | 男女操逼视频在线播放 | 欧美日韩在线视频免费播放 | 国产女处被破www免费 | 音彰先锋成人无码视频 |