Coder Social home page Coder Social logo

khtkjeg / phpboot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caoym/phpboot

0.0 1.0 0.0 549 KB

A lightweight and powerful PHP RESTful framework. :sparkles: 快速开发RESTful接口的框架:sparkles:

Home Page: https://caoym.gitbooks.io/phpboot/content/

License: MIT License

PHP 100.00%

phpboot's Introduction

PhpBoot

GitHub license Package version Build Status Scrutinizer Code Quality Code Coverage

phprs-restful 2.x 版本改名为PhpBoot。当前版本由于改动较大, 与1.x 版本不兼容。下载1.x版本请前往 phprs-restful v1.x

PhpBoot是专为开发RESTful API 设计的PHP框架。它设计的初衷是尽可能简化API开发,包括:

  • 更少的重复代码

    如避免为开发API而在文档、接口定义、实现、数据库设计之间不停的重复和同步代码等。

  • 更低的学习成本

    如尽量遵循优秀的惯例, 尽可能扩展PHP原生能力, 避免不必要的抽象等。

  • 更实用的功能

    如Validation、ORM、文档生成、工作流引擎等。同时使用PhpBoot有助于提高代码质量。

  • 更易于构建可扩展的应用

    如它引导面向接口的开发, 提倡强类型的编程方式, 提供依赖注入能力, 低侵入性的集成方式, 提供钩子机制等。

主要特性

安装和配置

  1. 安装composer(已安装可忽略)

    curl -s http://getcomposer.org/installer | php
    
  2. 安装PhpBoot

    composer require "caoym/phpboot"
    
  3. index.php加载PhpBoot

    <?php
    require __DIR__.'/vendor/autoload.php';
    
    $app = \PhpBoot\Application::createByDefault(__DIR__.'/config/config.php');
    $app->loadRoutesFromPath(__DIR__.'/App/Controllers');
    $app->dispatch();

示例

  下面一个最基本的例子, 展示了依赖注入、基于Anntotaion的路由定义、参数绑定、参数校验和ORM, 完整的示例请见phpboot-example,以及在线 Demo  

   /**
    * 图书管理接口示例
    *
    * @path /books
    */
   class Books
   {
       /**
        * 查找图书
        *
        * @route GET /
        *
        * @param string $name  查找书名
        * @param int $offset 结果集偏移 {@v min|0}
        * @param int $limit 返回结果最大条数 {@v max|1000}
        *
        * @throws BadRequestHttpException 参数错误
        * @return Book[] 图书列表 
        */
       public function findBooks($name, $offset=0, $limit=100)
       {
           return \PhpBoot\model($this->db, Book::class)
               ->where(['name'=>['LIKE'=>"%$name%"]])
               ->limit($offset, $limit)
               ->get();
       }
   }

对应请求和响应

$ curl http://localhost/books/?name=PHP&offset=0&limit=10
[
   {
       "id": 1,
       "name": "PHP",
          "brief": "PHP 从入门到嫌弃",
       "pictures": []
   }
]

帮助和文档

phpboot's People

Contributors

gitbook-bot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.