nirvana72/phprest

此包的最新版本(1.0.19)没有可用的许可证信息。

PhpRest 是一款纯 RESTful 的轻量级框架

1.0.19 2021-12-25 18:01 UTC

This package is auto-updated.

Last update: 2024-09-26 00:52:23 UTC


README

PhpRest 是一款纯 RESTful 的轻量级框架,此框架参考自 caoym/phpboot

<?php
namespace App\Controller;

class IndexController
{
    /**
     * @route GET /
     */
    public function index($p1) 
    {
        return "p1 = {$p1}";
    }
}

swagger

框架特点

  • 注释即代码,代码即文档
  • 自动路由
  • 依赖注入
  • 参数绑定
  • 丰富的验证封装
  • Swagger 完美支持

环境需求

  • PHP >= 7.3

安装

composer require nirvana72/phpRest

nginx 配置

server {
    listen 80;
    server_name example.com;
    index index.php;
    root /path/to/public;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }
}

apache 配置

开启 mod_rewrite 模块,入口目录(/public) 下添加 .htaccess 文件:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

文档

文笔不好,直接看示例代码。或直接下载示例项目 phpRest-example

参数绑定

参数绑定实体类

中间件 hook

数据库操作

ORM

Swagger

文件上传

事件驱动

其它

框架默认缓存实现是文件缓存(Filesystem),生产环境推荐安装 apcu 扩展