linkfast / exengine
适用于PHP 5.6+的微框架
Requires
- php: >=5.6.0
- ext-json: *
- monolog/monolog: 1.25.1
Suggests
- linkfast/eedbm: Lightweight database manager and ORM for PHP that uses PDO to interact with native DB connections.
- linkfast/zero-template: Lightweight template rendering engine.
- webonyx/graphql-php: Adds GraphQL support, a modern way to build HTTP APIs consumed by web and mobile clients.
README
ExEngine 是一个专为PHP 5.6+设计的超轻量级微服务框架。
文档
示例
点击这里浏览示例,你也可以克隆此仓库并运行它们。
快速开始
使用
composer
或 下载发布版 进行安装。composer require linkfast/exengine
创建实例启动器
在暴露给HTTP服务器的文件夹根目录下创建一个
index.php
文件,如果使用composer
,请包含vendor.php
或exengine.php
文件。<?php include_once 'exengine.php'; // or include_once 'vendor/autoload.php'; new \ExEngine\CoreX(__DIR__);
你可以创建一个自定义的带有设置的
config
类。在
index.php
相对路径下创建一个名为App
的文件夹。在这个新文件夹内,创建一个名为Test.php
的文件,内容如下:<?php # File ´._/Test.php´ class Test { function helloworld() { return "<h1>Hello World</h1>"; } }
打开浏览器并导航到:
http://myserverhost/index.php/Test/helloworld
查看
Examples
文件夹,获取收益。
创建REST控制器
ExEngine 允许轻松创建REST控制器,你只需扩展父类并编写HTTP方法响应。
<?php
class RestExample extends \ExEngine\RestController {
function get($id) {
return "Hello $id";
}
function post() {
$data = $_POST['data'];
return "Data: $data";
}
// function put()
// function delete()
// function options()
// etc.
}
使用标准HTTP方法测试REST控制器
GET http://myserverhost/index.php/RestExample/1
POST http://myserverhost/index.php/RestExample/
OPTIONS http://myserverhost/index.php/RestExample/
编写JSON API
ExEngine 将除 strings
函数结果外的所有内容转换为JSON,并将其封装在标准响应中。
示例成功响应
{
"took":0,
"code":200,
"data":{
"response": "from",
"the": "function"
},
"error":false
}
要获取前面的响应,你应该编写以下函数
// ...
function test() {
return [
"response" => "from",
"the" => "function"
]
}
问题
请使用此 链接 在我们的GitLab.com项目上提交一个问题。
关于GitHub仓库
GitHub仓库是我们GitLab仓库的实时同步镜像。你可以自由地使用它们中的任何一个作为你的源。
请记住,文档和问题跟踪器托管在我们的GitLab仓库中。
许可证
The MIT License (MIT)
Copyright (c) 2018-2020 LinkFast S.A. (http://linkfast.io)
Copyright (c) 2018-2020 Giancarlo A. Chiappe Aguilar (gchiappe@linkfast.io)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.