loandbeholdru/slimcontrol
Composer 安装命令:
composer require loandbeholdru/slimcontrol
包简介
Toolset to fast build REST API with SlimPHP
README 文档
README
Toolset to fast build Slimphp REST api
Installation
It's recommended that you use Composer to install SlimControl.
$ composer require loandbeholdru/slimcontrol
TODO / in progress
Package include many functions which i use more than 5 years, but this README so poor.
Documentation in progress ...
Usage
Fast build controller
class postreport extends controllerApi
{
const IN = ["report", "key", "data"];
const ASSERT = ["report", "key" => "keycheck"];
const DEFAULT = ["report" => "setdef"]
protected function process()
{
// You can do it because all opts are checked
extract($this->args);
return $this->replyjson(compact('report', 'key', 'data'));
}
// assert key
protected function keycheck($parameter, $valifexist){
return $valifexist === "notwrongkey";
}
// set default val of report if it's absent
protected function setdef($parameter){
return "default val of report";
}
}
Instead of using constants, you can override 3 methods:
//...
protected function defs()
{
return static::DEFAULTS;
}
protected function ins()
{
return static::IN;
}
protected function asss()
{
return static::ASSERT;
}
...
Simple reply for request
$this->replyjson($message, string $status = statuses::SUCCESS, int $code = 200)
Return follow with 200 OK:
{
"message" : "...",
"status" : "success"
}
Predefined statuses:
class statuses
{
const SUCCESS = 'success';
const ERROR = 'error';
const AUTH_FAIL = 'auth_fail';
const DB_ERROR = 'db_error';
const REQUEST_ERROR = 'request_error';
const DISK_ERROR = 'disk_error';
}
Few interesting middlewares
... documentation to be continued
Contributions
... are always welcome. Many times it is useful to just point out a use case the author have not thought about or come across.
统计信息
- 总下载量: 61
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-12-02