PhpBoot is an easy and powerful PHP framework for building RESTful/Microservices APIs.

Overview

PhpBoot

GitHub license Package version Documentation Status Build Status Scrutinizer Code Quality Code Coverage

phprs-restful 2.x is renamed to PhpBoot, and incompatible with 1.x. You can get the old version from phprs-restful v1.x

查看中文说明

PhpBoot is an easy and powerful PHP framework for building RESTful/Microservices APIs.

Specialities

PhpBoot provides mainstream features, such as IOC, HOOK, ORM, Validation, etc. But the most striking features are:

1. Designing object-oriented APIs

WITHOUT PhpBoot:

class BookController
{
    public function findBooks(Request $request)
    {
        $name = $request->get('name');
        $offset = $request->get('offset', 0);
        $limit = $request->get('limit', 10);
        ...
        return new Response(['total'=>$total, 'data'=>$books]);
    }
    
    public function createBook(Request $request)
    ...
}

WITH PhpBoot:

/**
 * @path /books/
 */
class Books
{
    /**
     * @route GET /
     * @return Book[]
     */
    public function findBooks($name, &$total=null, $offset=0, $limit=10)
    {
        $total = ...
        ...
        return $books;
    }
  
    /**
     * @route POST /
     * @param Book $book {@bind request.request} bind $book with http body
     * @return string id of created book
     */
    public function createBook(Book $book)
    {
        $id = ... 
        return $id;
    }
}

Read more: phpboot-example。    

2. Swagger

PhpBoot can automatically generate Swagger JSON,which can be rendered as document by Swagger UI like this:

Read more: Online Demo

3. RPC

Call the remote Books with RPC:

$books = $app->make(RpcProxy::class, [
        'interface'=>Books::class, 
        'prefix'=>'http://x.x.x.x/'
    ]);
    
$books->findBooks(...);

Concurrent call RPC:

$res = MultiRpc::run([
    function()use($service1){
        return $service1->doSomething();
    },
    function()use($service2){
        return $service2->doSomething();
    },
]);

Read more: RPC

4. IDE friendly

Features

Installation

  1. Install composer

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

    composer require "caoym/phpboot"
    
  3. index.php

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

Help & Documentation

Comments
  • 关于路由映射与代码组织的矛盾

    关于路由映射与代码组织的矛盾

    假设有两个API

    1. Get /users/100/Devices
    2. Get /catalogs/200/Devices

    按照 phprs 的规则,应该放在不同的文件中,如 users.php, catalogs.php 但是两个api处理的资源都是Device, 似乎又应该放在一个文件中。 实践上怎么处理比较好?

    opened by dearbird 4
  • 如果api在子目录怎么办

    如果api在子目录怎么办

    比如我的所有api,希望放在api这个子目录,然后调用: http://www.xxxx.com/api/hw/

    现在提示“File not found.”

    我在nginx中配置: server { listen 80; server_name www.xxxx.com; root /Users/hqr/shopping/m4;

        location / {
            root   /Users/hqr/shopping/m4;
            index  index.php;
        }
        location /api {
            root   /Users/hqr/shopping/m4;
            index  index.php;
            try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
            root           /Users/hqr/shopping/m4;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    不知道应该如何配置了

    opened by tigerohuang 3
  • How about add 401 unAuth error response

    How about add 401 unAuth error response

    I need to info user to input the credentials via Basic auth. current phprs-restful version support 403 only. may I ask for 401 response? or I can help to do the implementation as long as the author agree for that.

    opened by januslo 2
  • Class App\Controllers\Books does not exist

    Class App\Controllers\Books does not exist

    win10 nginx php7.3 composer 安装好依赖,git 拉取example 项目 目录结构,拉取后就没动用 App -Controllers --Books.php config public vendor composer.json

    运行项目报错 Fatal error: Uncaught ReflectionException: Class App\Controllers\Books does not exist in E:\php\phpboot\vendor\caoym\phpboot\src\Annotation\ContainerBuilder.php:42 Stack trace: #0 E:\php\phpboot\vendor\caoym\phpboot\src\Annotation\ContainerBuilder.php(42): ReflectionClass->__construct('App\Controllers...') #1 E:\php\phpboot\vendor\caoym\phpboot\src\Controller\ControllerContainerBuilder.php(62): PhpBoot\Annotation\ContainerBuilder->build('App\Controllers...') #2 E:\php\phpboot\vendor\caoym\phpboot\src\Application.php(153): PhpBoot\Controller\ControllerContainerBuilder->build('App\Controllers...') #3 E:\php\phpboot\vendor\caoym\phpboot\src\Application.php(213): PhpBoot\Application->loadRoutesFromClass('App\Controllers...', Array) #4 E:\php\phpboot\public\index.php(37): PhpBoot\Application->loadRoutesFromPath('E:/php/phpboot/...', 'App\Controllers') #5 {main} thrown in E:\php\phpboot\vendor\caoym\phpboot\src\Annotation\ContainerBuilder.php on line 42


    请教一下, 是我哪个地方遗漏了么

    opened by nirvana72 1
  • 求助,

    求助,"error":"phprs\\util\\exceptions\\NotFound","message

    `<?php header("Content-Type:text/html;charset=utf-8"); use phprs\ezsql\Sql;

    /** *

    • @author caoym

    • @path("/wwwwwww") / class HelloWorld2 { /*

      • @route({"GET","/"})

      • @param({"arg0","$._GET.arg0"}) */ public function doSomething1() { try{ $pdo = $this->db; $str = Sql::update('report')->set( 'lv = 1' )->where('id=?',$arg0)->exec($pdo); $pdo->commit(); } catch (Exception $e) {

         $pdo->rollBack();
         throw $e;
        

        } return "1";
        }

      /**

      • @property({"default":"@db"}) 注入pdo实例 */ public $db; } `

    这是我在phprs-restful-master\example\apis目录下新建的Helloworld2.php 文件 不知道为什么访问会报 3 0.0202 877496 header ( ) ..\Bootstrap.php:42 {"error":"phprs\util\exceptions\NotFound","message":""} 我把 HelloWorld.php 内容改成了 `<?php header("Content-Type:text/html;charset=utf-8"); use phprs\ezsql\Sql;

    /** *

    • @author caoym

    • @path("/g") / class HelloWorld { /*

      • @route({"GET","/"}) / public function doSomething1() { $str = Sql::select('')->from('report')->where( 'lv = 0' )->limit(1,1)->get($this->db); $str1= json_encode($str, JSON_UNESCAPED_UNICODE);
        return $str1;
        }

      /**

      • @property({"default":"@db"}) 注入pdo实例 */ public $db; }`

    这样访问又没有问题。真是奇怪, 配置文件 phprs-restful-master\example\conf.php内容 `<?php return [ "phprs\Router"=>[ "properties"=>[ "export_apis"=>true, "url_begin"=>1, "api_path"=>DIR.'/apis/',

        ]
    ],
    "phprs\\Invoker"=>[
        "properties"=>[
            
        ] 
    ],
    "db"=>[
    	"singleton"=>true,
    	"class"=>"PDO",
    	"pass_by_construct"=>true,
    	"properties"=>[
    		"dsn"=>"mysql:host=127.0.0.1;dbname=report;charset=UTF8",
    		"username"=>"root",
    		"passwd"=>"xxx"  		
    	]
    ]
    

    ]; `

    opened by admimistrator 1
  • 如何自定义配置段

    如何自定义配置段

    我有一段自定义的配置,放在conf.php 里面,如何在实现api的时候方便的读取? 在conf.php 中

    ,"myconfig"=> [
            "name"=> "william",
            "url"=> "http://william.abc.com"
     ]
    
    

    在api.php 中 可否

    
    /**
     * @property
     */
    private $myconfig;  //  此处自动关联到配置项
    
    
    opened by dearbird 1
  • how to create the database table for example/users?

    how to create the database table for example/users?

    > POST /apis/users/ HTTP/1.1
    > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
    > Host: xxxx.com
    > Accept: */*
    > Cookie:token=12345
    > Content-Length: 41
    > Content-Type: application/x-www-form-urlencoded
    > 
    < HTTP/1.1 200 OK
    < Server: nginx/1.4.6 (Ubuntu)
    < Date: Wed, 17 Aug 2016 18:09:33 GMT
    < Content-Type: text/html
    < Transfer-Encoding: chunked
    < Connection: keep-alive
    < X-Powered-By: PHP/5.5.9-1ubuntu4.19
    < 
    <br />
    <b>Fatal error</b>:  Uncaught exception 'ReflectionException' with message 'Cannot determine default value for internal functions' in ~/phprs/lib/phprs/util/IoCFactory.php:287
    Stack trace:
    #0 ~/phprs/lib/phprs/util/IoCFactory.php(287): ReflectionParameter-&gt;getDefaultValue()
    #1 ~/phprs/lib/phprs/util/IoCFactory.php(138): phprs\util\IoCFactory-&gt;buildConstructArgs(Object(ReflectionClass), Array)
    #2 ~/phprs/lib/phprs/util/IoCFactory.php(300): phprs\util\IoCFactory-&gt;create('db')
    #3 ~/phprs/lib/phprs/util/IoCFactory.php(400): phprs\util\IoCFactory-&gt;getProperty('@db')
    #4 ~/phprs/lib/phprs/util/IoCFactory.php(167): phprs\util\IoCFactory-&gt;injectDependent(Object(ReflectionClass), Object(Users), Array, Array, Object(Closure))
    #5 ~/phprs/lib/phprs/Container.php(112): phprs\util\IoCFactory-&gt;create('Users', NULL, NULL, Object(Closure))
    #6 ~/phprs/lib/phprs/Invoker.php(145): phprs\Container-&gt;getImpl(Object(phprs\Request))
    #7 ~/phprs/lib/phprs/Router.php(198): phprs in <b>~/phprs/lib/phprs/util/IoCFactory.php</b> on line <b>287</b><br />
    * Connection #0 to host yurenchen.com left intact
    * Closing connection #0
    

    seems database table need initial ? (i use 1.2.2)

    opened by yurenchen000 1
  • undue sql wrap with ``

    undue sql wrap with ``

    The following code generating wrong SQL

    $db->select('books.id')->from('books')
    

    Current wrong SQL

    select `books.id` from `books`
    

    expected correct SQL

    select books.id from `books`
    
    opened by caoym 0
  • update code

    update code

    1. catch exception at bootstrap to catch both hook and api.
    2. add two new exception, NotAcceptable and Ratelimit .
    3. add get_row and get_var to db impls for convenient.
    opened by dearbird 0
Releases(v2.1.1)
Production ready Dockerfile for Octane powered Laravelish web services and microservices

Laravel Octane Dockerfile A pretty configurable and production ready multi-stage Dockerfile for Octane powered Laravelish web services and microservic

Exalab.co 213 Sep 22, 2022
PHP MicroServices Examples

PHP MicroServices Examples This is a repo of example MicroServices using PHP. Areas of topics will include: Socket Programming RabbitMQ Example RESTFU

Pradeep Sahoo 0 Aug 29, 2022
Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily.

Leaf is a PHP framework that helps you create clean, simple but powerful web apps and APIs quickly and easily. Leaf introduces a cleaner and much simpler structure to the PHP language while maintaining it's flexibility. With a simple structure and a shallow learning curve, it's an excellent way to rapidly build powerful and high performant web apps and APIs.

Leaf Framework 654 Sep 27, 2022
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

Slim Framework 11.4k Sep 23, 2022
TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

TrailLamp Introduction TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs. Installatio

Etorojah Okon 14 Jun 10, 2022
A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast! Condensed in a single ~65KB file

Bong Cosca 2.6k Sep 25, 2022
Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X – the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Christian Lück 568 Sep 20, 2022
A Restful PHP Microservice Framework!

SLIM 4 FRAMEWORK Introduction This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api. Featur

POABOB 4 Aug 4, 2022
A Restful PHP Microservice Framework!

SLIM 4 FRAMEWORK Introduction This project was built with php SLIM 4 framework with ADR mode, whcich is a compatible resolution of RESTful Api. Featur

POABOB 4 Aug 4, 2022
Volistx Framework For RESTful API Based on Laravel/Lumen 9.x

Volistx Framework Volistx Framework For RESTful API Based on Laravel/Lumen 9.x This is a framework skeleton for Volistx API platform using Lumen PHP F

Volistx Solutions 2 Apr 23, 2022
FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Ruby on Rails.

FlyCubePHP FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Rub

Anton 1 Dec 21, 2021
Sunhill Framework is a simple, fast, and powerful PHP App Development Framework

Sunhill Framework is a simple, fast, and powerful PHP App Development Framework that enables you to develop more modern applications by using MVC (Model - View - Controller) pattern.

Mehmet Selcuk Batal 2 Aug 6, 2022
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.

Woski is a simple fast PHP framework for the Realm The Project Installation Clone the repository $ composer create-project clintonnzedimma/woski myApp

Clinton Nzedimma 19 Aug 15, 2022
Framework for building extensible server-side progressive applications for modern PHP.

Chevere ?? Subscribe to the newsletter to don't miss any update regarding Chevere. Framework for building extensible server-side progressive applicati

Chevere 59 Aug 26, 2022
Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight-PHP-Framework-For-APIs. Simple PHP framework that helps you quickly understand and write simple APIs. Installation Use the package manager

Youssef Hajjari 24 Jul 22, 2022
Simple PHP framework that helps you quickly understand and write simple APIs.

Lightweight PHP Framework For Web and APIs PHP framework that helps you write quickly simple but powerful web apps and APIs Installation Use the packa

Youssef Hajjari 24 Jul 22, 2022
REST APIs using Slim framework. Implemented all CRUD operations on the MySql database

PHP REST API using slim framework and CRUD operations ?? Hi there, this is a simple REST API built using the Slim framework. And this is for the folks

Hanoak 2 Jun 1, 2022
PHP Kafka client is used in PHP-FPM and Swoole. PHP Kafka client supports 50 APIs, which might be one that supports the most message types ever.

longlang/phpkafka Introduction English | 简体中文 PHP Kafka client is used in PHP-FPM and Swoole. The communication protocol is based on the JSON file in

Swoole Project 223 Sep 23, 2022
a framework for WebDevelop based on the mvc structure. The name of this project for Fun because everyone can use it. Completely simple and powerful structure for all your projects

A_A (-.-) ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ |-| █▄─▄▄─█▄─██─▄█─▄▄▄▄█─▄▄▄▄█▄─█─▄█─▄▄▄─██▀▄─██─▄

MasihGhaznavi 7 Jun 29, 2022