pmurkin/bootstrapi

这是我的 JSON API 框架。使用 Slim 3, Eloquent, Zend-ACL 构建

安装: 209

依赖: 0

建议者: 0

安全: 0

星星: 88

关注者: 15

分支: 22

开放问题: 4

类型:项目

dev-master 2018-05-19 12:56 UTC

This package is auto-updated.

Last update: 2024-09-29 04:25:48 UTC


README

Gitter Build Status Scrutinizer Code Quality Total Downloads License

bootstrapi

更好的 PHP API 框架。使用 Slim 3, Eloquent, Zend-ACL 构建

功能

  • JWT 认证
  • 验证请求
  • 基于 ACL 的角色
  • 支持基本的 CRUD 操作
  • 过滤 && 排序 && 分页
  • 数据库迁移
  • CLI 工具
  • JSONAPI 协商
  • 生成文档
  • 代码生成命令
  • 日志

内部

演示

示例文档

示例客户端(Ember.js 应用程序)

客户端仓库

要求

  • PHP >= 5.6
  • Composer
  • Nginx / Apache
  • MySQL / PostgreSQL
  • NodeJs && NPM && ApiDocJs(用于生成文档)

捐赠

比特币支付:1LLw4WuBz1oUSjQFntfQutD2T8mGZiA7pZ

安装

  1. 创建新项目
$ composer create-project -n -s dev pmurkin/bootstrapi my-api
  1. 修改配置文件
$ nano .env
$ nano config/apidoc.php
$ nano version.sh
  1. 配置服务器

nginx 示例配置

server {
    listen 80 ;
    server_name     hostname;
    error_log       /path/to/nginx/logs/hostname.error.log;
    access_log      /path/to/nginx/logs/hostname.access.log;
    index           /frontend/index.html index.html;

    root   /path/to/projects/hostname;

    location ~* (.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|woff2|ttf|eot|svg))$ {
        root   /path/to/projects/hostname/frontend;
        try_files       $uri =404;
    }

    location ~ /api/ {
        if (!-e $request_filename) {rewrite ^/(.*)$ /public/index.php?q=$1 last;}
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_pass   127.0.0.1:9000;
    }

    location / {
        if (!-e $request_filename) {rewrite ^/(.*)$ /frontend/index.html?q=$1 last;}
    }
}

server {
    listen 80 ;
    server_name     docs.hostname;
    error_log       /path/to/nginx/logs/hostname.error.log;
    access_log      /path/to/nginx/logs/hostname.access.log;
    index           index.html;
    root            /path/to/projects/hostname/docs;

    location / {
        try_files $uri $uri/ /index.html?$args;
    }

    location ~* (.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|woff2|ttf|eot|svg))$ {
        try_files $uri =404;
    }
}

server {
    listen 80 ;
    server_name     static.hostname;
    error_log       /path/to/nginx/logs/hostname.error.log;
    access_log      /path/to/nginx/logs/hostname.access.log;

    root            /path/to/projects/hostname/public/uploads;

    location ~* (.+\.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar|woff|woff2|ttf|eot|svg))$ {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
        try_files $uri =404;
    }
}

apache 示例配置

<VirtualHost *:80>
   ServerName hostname
   DocumentRoot "/path/to/projects/hostname/"

   <Directory "/path/to/projects/hostname/public/">
       # use mod_env for define environment variables
       SetEnv APPLICATION_ENV develop
       SetEnv SECRET_KEY mysecretkey
   
       # use mod_rewrite for pretty URL support
       RewriteEngine on
       # If a directory or a file exists, use the request directly
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       # Otherwise forward the request to index.php
       RewriteRule ^api/(.*)$ /index.php?q=$1 [L]

       # use index.php as index file
       DirectoryIndex index.php

       # ...other settings...
       # Apache 2.4
       Require all granted

       ## Apache 2.2
       # Order allow,deny
       # Allow from all
   </Directory>
</VirtualHost>

<VirtualHost *:80>
   ServerName docs.hostname
   DocumentRoot "/path/to/projects/hostname/docs"

   <Directory "/path/to/projects/hostname/docs">
       # use index.html as index file
       DirectoryIndex index.html

       # ...other settings...
       # Apache 2.4
       Require all granted

       ## Apache 2.2
       # Order allow,deny
       # Allow from all
   </Directory>
</VirtualHost>
  1. 迁移
$ php partisan migrate:up
  1. 迁移
$ php partisan run:seed
  1. 生成文档(可选)
$ php partisan generate:docs