Skip to content
Avatar
Block or Report

Block or report phalapi

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Add an optional note:
Please don't include any personal information such as legal names or email addresses. Maximum 100 characters. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
phalapi/README.md

apic

PhalApi开源接口框架 / PhalApi API Framework

读音:派框架,官网:https://www.phalapi.net/

Latest Stable Version Total Downloads Latest Unstable Version License

Stargazers over time

Stargazers over time

开发文档

专为PHPer准备的优雅而详细的开发文档,基本都能在文档找到你要的答案,请看:PhalApi 2.x 开发文档

在线示例

快速安装

composer一键安装

使用composer创建项目的命令,可实现一键安装。

$ composer create-project phalapi/phalapi

温馨提示:关于composer的使用,请参考Composer 中文网 / Packagist 中国全量镜像

手动下载安装

或者,也可以进行手动安装。将此Git项目代码下载解压后,进行可选的composer更新,即:

$ composer update

部署

Nginx配置

如果使用的是Nginx,可参考以下配置。

server {
    listen 80;
    server_name dev.phalapi.net;
    # 将根目录设置到public目录
    root /path/to/phalapi/public;
    charset utf-8;

    location / {
        index index.php;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # 根据当前环境,选择合适的通讯方式
        # 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;
    }
}

配置时需要将网站根目录设置到public目录,配置保存后重启nginx。

温馨提示:推荐将访问根路径指向/path/to/phalapi/public。

数据库配置

如何使用的是MySQL数据库,参考修改./config/dbs.php数据库配置。

return array(
    /**
     * DB数据库服务器集群 / database cluster
     */
    'servers' => array(
        'db_master' => array(                       // 服务器标记 / database identify
            'type'      => 'mysql',                 // 数据库类型,暂时只支持:mysql, sqlserver / database type
            'host'      => '127.0.0.1',             // 数据库域名 / database host
            'name'      => 'phalapi',               // 数据库名字 / database name
            'user'      => 'root',                  // 数据库用户名 / database user
            'password'  => '',	                    // 数据库密码 / database password
            'port'      => 3306,                    // 数据库端口 / database port
            'charset'   => 'UTF8',                  // 数据库字符集 / database charset
            'pdo_attr_string'   => false,           // 数据库查询结果统一使用字符串,true是,false否
            'driver_options' => array(              // PDO初始化时的连接选项配置
                // 若需要更多配置,请参考官方文档:https://www.php.net/manual/zh/pdo.constants.php
            ),
        ),
    ),

    // 更多代码省略……
);

最后,需要给runtime目录添加写入权限。更多安装说明请参考文档下载与安装

使用

调用接口

在PhalApi,你可以通过service参数(短名字是s参数)指定需要调用的接口服务。例如,访问默认接口服务。

http://dev.phalapi.net/?s=App.Site.Index

接口请求后结果输出类似如下:

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

对应执行的PHP代码在./src/app/Api/Site.php文件,源码片段如下:

<?php
namespace App\Api;
use PhalApi\Api;

/**
 * 默认接口服务类
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */
class Site extends Api {
    public function getRules() {
        return array(
            'index' => array(
                'username'  => array('name' => 'username', 'default' => 'PhalApi', 'desc' => '用户名'),
            ),
        );
    }

    /**
     * 默认接口服务
     * @desc 默认接口服务,当未指定接口服务时执行此接口服务
     * @return string title 标题
     * @return string content 内容
     * @return string version 版本,格式:X.X.X
     * @return int time 当前时间戳
     * @exception 400 非法请求,参数传递错误
     */
    public function index() {
        return array(
            'title' => 'Hello ' . $this->username,
            'version' => PHALAPI_VERSION,
            'time' => $_SERVER['REQUEST_TIME'],
        );
    }
}

运行效果,截图如下:

_20190201151943

查看在线接口文档

PhalApi会根据你编写的接口的参数配置和代码注释,自动实时生成在线接口文档。在线接口文档链接为:

浏览效果类似如下:

接口文档详情页效果类似如下:
支持在线接口测试、请求示例说明、生成离线版HTML接口文档、实时更新。

翻译

修改./public/init.php文件,可设置当前语言。

// 翻译语言包设定-简体中文
\PhalApi\SL('zh_cn');

// Setting language to English
\PhalApi\SL('en');

一张图告诉你如何使用PhalApi 2.x

phalapi-install

2020视频教程

子项目

PhalApi composer 扩展

温馨提示:以上扩展需要先通过composer安装再使用。更多扩展类库的使用和开发,请参考文档:PhalApi框架扩展类库

PhalApi应用插件

温馨提示:应用插件和composer扩展的区别在于,应用插件颗粒度更大,功能更具体,可能不仅有数据库、接口、界面、还可能配合其他终端,并且不受composer的规范约束,是PhalApi自主发明和设计的开发方式。更多请参考:第三方应用插件开发教程

推荐产品

温馨提示:以上产品均使用了PhalApi开源框架,并为官方自主研发的产品,欢迎个人/团队/企业使用。

还有问题,怎么办?

如发现问题,或者任何问题,欢迎提交Issue到这里
如果喜欢,请帮忙在Github码云给个Star,也可以对PhalApi进行捐赠哦 ^_^。

开源许可协议 / Licence

Apache 2.0,Apache Licence是著名的非盈利开源组织Apache采用的协议。该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权,同样允许代码修改,再发布(作为开源或商业软件)。

由 广州果创网络科技有限公司 长期维护升级。

Pinned

  1. phalapi Public

    PhalApi开源接口框架,简称π框架,一个轻量级PHP开源接口框架,专注于接口服务开发。接口,从简单开始!

    JavaScript 1.5k 366

6 contributions in the last year

No contributions on February 6, 2022 No contributions on February 7, 2022 No contributions on February 8, 2022 No contributions on February 9, 2022 No contributions on February 10, 2022 No contributions on February 11, 2022 No contributions on February 12, 2022 No contributions on February 13, 2022 No contributions on February 14, 2022 No contributions on February 15, 2022 No contributions on February 16, 2022 No contributions on February 17, 2022 No contributions on February 18, 2022 No contributions on February 19, 2022 No contributions on February 20, 2022 No contributions on February 21, 2022 No contributions on February 22, 2022 No contributions on February 23, 2022 No contributions on February 24, 2022 No contributions on February 25, 2022 No contributions on February 26, 2022 No contributions on February 27, 2022 No contributions on February 28, 2022 No contributions on March 1, 2022 No contributions on March 2, 2022 No contributions on March 3, 2022 No contributions on March 4, 2022 No contributions on March 5, 2022 No contributions on March 6, 2022 No contributions on March 7, 2022 No contributions on March 8, 2022 No contributions on March 9, 2022 No contributions on March 10, 2022 No contributions on March 11, 2022 No contributions on March 12, 2022 No contributions on March 13, 2022 No contributions on March 14, 2022 No contributions on March 15, 2022 No contributions on March 16, 2022 No contributions on March 17, 2022 No contributions on March 18, 2022 No contributions on March 19, 2022 No contributions on March 20, 2022 No contributions on March 21, 2022 No contributions on March 22, 2022 No contributions on March 23, 2022 No contributions on March 24, 2022 No contributions on March 25, 2022 No contributions on March 26, 2022 No contributions on March 27, 2022 No contributions on March 28, 2022 No contributions on March 29, 2022 No contributions on March 30, 2022 No contributions on March 31, 2022 No contributions on April 1, 2022 No contributions on April 2, 2022 No contributions on April 3, 2022 No contributions on April 4, 2022 No contributions on April 5, 2022 No contributions on April 6, 2022 No contributions on April 7, 2022 No contributions on April 8, 2022 No contributions on April 9, 2022 No contributions on April 10, 2022 No contributions on April 11, 2022 No contributions on April 12, 2022 No contributions on April 13, 2022 No contributions on April 14, 2022 No contributions on April 15, 2022 No contributions on April 16, 2022 No contributions on April 17, 2022 No contributions on April 18, 2022 No contributions on April 19, 2022 No contributions on April 20, 2022 No contributions on April 21, 2022 No contributions on April 22, 2022 No contributions on April 23, 2022 No contributions on April 24, 2022 No contributions on April 25, 2022 No contributions on April 26, 2022 No contributions on April 27, 2022 No contributions on April 28, 2022 No contributions on April 29, 2022 No contributions on April 30, 2022 No contributions on May 1, 2022 No contributions on May 2, 2022 No contributions on May 3, 2022 No contributions on May 4, 2022 No contributions on May 5, 2022 1 contribution on May 6, 2022 No contributions on May 7, 2022 No contributions on May 8, 2022 No contributions on May 9, 2022 No contributions on May 10, 2022 No contributions on May 11, 2022 No contributions on May 12, 2022 No contributions on May 13, 2022 No contributions on May 14, 2022 No contributions on May 15, 2022 No contributions on May 16, 2022 No contributions on May 17, 2022 No contributions on May 18, 2022 No contributions on May 19, 2022 No contributions on May 20, 2022 No contributions on May 21, 2022 No contributions on May 22, 2022 No contributions on May 23, 2022 No contributions on May 24, 2022 No contributions on May 25, 2022 No contributions on May 26, 2022 No contributions on May 27, 2022 No contributions on May 28, 2022 No contributions on May 29, 2022 No contributions on May 30, 2022 No contributions on May 31, 2022 No contributions on June 1, 2022 No contributions on June 2, 2022 No contributions on June 3, 2022 No contributions on June 4, 2022 No contributions on June 5, 2022 No contributions on June 6, 2022 No contributions on June 7, 2022 No contributions on June 8, 2022 No contributions on June 9, 2022 No contributions on June 10, 2022 No contributions on June 11, 2022 No contributions on June 12, 2022 No contributions on June 13, 2022 No contributions on June 14, 2022 No contributions on June 15, 2022 No contributions on June 16, 2022 No contributions on June 17, 2022 No contributions on June 18, 2022 No contributions on June 19, 2022 No contributions on June 20, 2022 No contributions on June 21, 2022 No contributions on June 22, 2022 No contributions on June 23, 2022 No contributions on June 24, 2022 No contributions on June 25, 2022 No contributions on June 26, 2022 No contributions on June 27, 2022 No contributions on June 28, 2022 No contributions on June 29, 2022 No contributions on June 30, 2022 No contributions on July 1, 2022 No contributions on July 2, 2022 No contributions on July 3, 2022 No contributions on July 4, 2022 No contributions on July 5, 2022 No contributions on July 6, 2022 No contributions on July 7, 2022 No contributions on July 8, 2022 No contributions on July 9, 2022 No contributions on July 10, 2022 No contributions on July 11, 2022 No contributions on July 12, 2022 No contributions on July 13, 2022 No contributions on July 14, 2022 No contributions on July 15, 2022 No contributions on July 16, 2022 No contributions on July 17, 2022 No contributions on July 18, 2022 No contributions on July 19, 2022 No contributions on July 20, 2022 No contributions on July 21, 2022 No contributions on July 22, 2022 No contributions on July 23, 2022 No contributions on July 24, 2022 No contributions on July 25, 2022 No contributions on July 26, 2022 No contributions on July 27, 2022 No contributions on July 28, 2022 No contributions on July 29, 2022 No contributions on July 30, 2022 No contributions on July 31, 2022 No contributions on August 1, 2022 No contributions on August 2, 2022 No contributions on August 3, 2022 No contributions on August 4, 2022 No contributions on August 5, 2022 No contributions on August 6, 2022 No contributions on August 7, 2022 No contributions on August 8, 2022 No contributions on August 9, 2022 No contributions on August 10, 2022 No contributions on August 11, 2022 No contributions on August 12, 2022 No contributions on August 13, 2022 No contributions on August 14, 2022 No contributions on August 15, 2022 No contributions on August 16, 2022 No contributions on August 17, 2022 No contributions on August 18, 2022 No contributions on August 19, 2022 No contributions on August 20, 2022 No contributions on August 21, 2022 No contributions on August 22, 2022 No contributions on August 23, 2022 No contributions on August 24, 2022 No contributions on August 25, 2022 No contributions on August 26, 2022 No contributions on August 27, 2022 No contributions on August 28, 2022 No contributions on August 29, 2022 No contributions on August 30, 2022 No contributions on August 31, 2022 No contributions on September 1, 2022 No contributions on September 2, 2022 No contributions on September 3, 2022 No contributions on September 4, 2022 No contributions on September 5, 2022 No contributions on September 6, 2022 No contributions on September 7, 2022 No contributions on September 8, 2022 No contributions on September 9, 2022 No contributions on September 10, 2022 No contributions on September 11, 2022 No contributions on September 12, 2022 No contributions on September 13, 2022 No contributions on September 14, 2022 No contributions on September 15, 2022 No contributions on September 16, 2022 No contributions on September 17, 2022 No contributions on September 18, 2022 No contributions on September 19, 2022 No contributions on September 20, 2022 No contributions on September 21, 2022 No contributions on September 22, 2022 No contributions on September 23, 2022 No contributions on September 24, 2022 No contributions on September 25, 2022 No contributions on September 26, 2022 No contributions on September 27, 2022 No contributions on September 28, 2022 No contributions on September 29, 2022 No contributions on September 30, 2022 No contributions on October 1, 2022 No contributions on October 2, 2022 No contributions on October 3, 2022 No contributions on October 4, 2022 No contributions on October 5, 2022 No contributions on October 6, 2022 No contributions on October 7, 2022 No contributions on October 8, 2022 No contributions on October 9, 2022 No contributions on October 10, 2022 No contributions on October 11, 2022 No contributions on October 12, 2022 No contributions on October 13, 2022 No contributions on October 14, 2022 No contributions on October 15, 2022 2 contributions on October 16, 2022 No contributions on October 17, 2022 No contributions on October 18, 2022 No contributions on October 19, 2022 No contributions on October 20, 2022 No contributions on October 21, 2022 No contributions on October 22, 2022 No contributions on October 23, 2022 No contributions on October 24, 2022 No contributions on October 25, 2022 No contributions on October 26, 2022 No contributions on October 27, 2022 No contributions on October 28, 2022 No contributions on October 29, 2022 No contributions on October 30, 2022 No contributions on October 31, 2022 No contributions on November 1, 2022 No contributions on November 2, 2022 No contributions on November 3, 2022 No contributions on November 4, 2022 No contributions on November 5, 2022 No contributions on November 6, 2022 No contributions on November 7, 2022 No contributions on November 8, 2022 No contributions on November 9, 2022 No contributions on November 10, 2022 No contributions on November 11, 2022 No contributions on November 12, 2022 No contributions on November 13, 2022 No contributions on November 14, 2022 No contributions on November 15, 2022 No contributions on November 16, 2022 No contributions on November 17, 2022 No contributions on November 18, 2022 No contributions on November 19, 2022 No contributions on November 20, 2022 No contributions on November 21, 2022 No contributions on November 22, 2022 No contributions on November 23, 2022 No contributions on November 24, 2022 No contributions on November 25, 2022 No contributions on November 26, 2022 No contributions on November 27, 2022 No contributions on November 28, 2022 No contributions on November 29, 2022 No contributions on November 30, 2022 No contributions on December 1, 2022 No contributions on December 2, 2022 No contributions on December 3, 2022 No contributions on December 4, 2022 No contributions on December 5, 2022 No contributions on December 6, 2022 No contributions on December 7, 2022 1 contribution on December 8, 2022 No contributions on December 9, 2022 No contributions on December 10, 2022 No contributions on December 11, 2022 No contributions on December 12, 2022 No contributions on December 13, 2022 No contributions on December 14, 2022 No contributions on December 15, 2022 No contributions on December 16, 2022 No contributions on December 17, 2022 No contributions on December 18, 2022 No contributions on December 19, 2022 No contributions on December 20, 2022 No contributions on December 21, 2022 No contributions on December 22, 2022 No contributions on December 23, 2022 No contributions on December 24, 2022 No contributions on December 25, 2022 No contributions on December 26, 2022 No contributions on December 27, 2022 No contributions on December 28, 2022 No contributions on December 29, 2022 No contributions on December 30, 2022 No contributions on December 31, 2022 No contributions on January 1, 2023 No contributions on January 2, 2023 No contributions on January 3, 2023 No contributions on January 4, 2023 No contributions on January 5, 2023 No contributions on January 6, 2023 No contributions on January 7, 2023 No contributions on January 8, 2023 No contributions on January 9, 2023 No contributions on January 10, 2023 No contributions on January 11, 2023 No contributions on January 12, 2023 No contributions on January 13, 2023 No contributions on January 14, 2023 No contributions on January 15, 2023 No contributions on January 16, 2023 No contributions on January 17, 2023 No contributions on January 18, 2023 No contributions on January 19, 2023 No contributions on January 20, 2023 No contributions on January 21, 2023 No contributions on January 22, 2023 No contributions on January 23, 2023 No contributions on January 24, 2023 No contributions on January 25, 2023 No contributions on January 26, 2023 No contributions on January 27, 2023 No contributions on January 28, 2023 No contributions on January 29, 2023 No contributions on January 30, 2023 No contributions on January 31, 2023 No contributions on February 1, 2023 No contributions on February 2, 2023 No contributions on February 3, 2023 No contributions on February 4, 2023 No contributions on February 5, 2023 2 contributions on February 6, 2023 No contributions on February 7, 2023 No contributions on February 8, 2023 No contributions on February 9, 2023 Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan Mon Wed Fri

Contribution activity

February 2023

Created 1 repository
Opened 1 pull request in 1 repository
apistd/uni-php-sdk 1 open

Seeing something unexpected? Take a look at the GitHub profile guide.