Coder Social home page Coder Social logo

caoym / phpboot Goto Github PK

View Code? Open in Web Editor NEW
659.0 659.0 175.0 1.16 MB

:coffee: 🚀 tiny & fast PHP framework for building Microservices/RESTful APIs, with useful features: IOC, Hook, ORM, RPC, Swagger, Annotation, Parameters binding, Validation, etc.

Home Page: http://phpboot.org

License: MIT License

PHP 100.00%
annotation framework microservices orm restful rpc swagger

phpboot's People

Contributors

caoyangmin avatar freezjx avatar gaoolp avatar gitbook-bot avatar jiangslee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpboot's Issues

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

假设有两个API

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

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

求助,"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"  		
	]
]

];
`

想做一个签名校验

想做一个签名校验,应该放在哪里做,初步想用用户名,密码,和当前时间戳做一个MD5加密做一个签名验证方法

关于APC扩展

是否为必需组件?自PHP7开始只兼容APCu,据我了解应该是跟OPcache差不多作用的缓存扩展。看缓存章节说用APC来缓存一些元信息,那么用APCu代替可以吗?

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)

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.

如何自定义配置段

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

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

在api.php 中
可否


/**
 * @property
 */
private $myconfig;  //  此处自动关联到配置项

error

{
error: "caoym\util\exceptions\NotFound",
message: ""
}

路由算法需要增加严格匹配模式

目前的算法是使用最接近的路由,但是不合理

  • GET /devices
  • GET /devices/**
    当第二个是错误的路由的时候,却会返回第一个路由的结果,应该返回404.

如何在hook和api之间传递变量?

hook中实现了用户验证,同时获取的用户的信息,这些信息需要在各个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;
    }
}

不知道应该如何配置了

有版本功能吗?

简单易用,确实不错,赞~
请问有接口版本功能吗?方便不同的接口调用方调用与切换··

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`

conf.json 可能泄漏

由于index与confi.json 文件在同一目录下,可以直接输入url进行下载。

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


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

找不到类的报错

刚配置项目的时候出了个找不到类报错,不知道什么原因,然后自己在中间加了个引用类文件好了。

框架很好用,很期待!

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.