loandbeholdru / slimcontrol
Toolset to fast build REST API with SlimPHP
    dev-master
    2023-06-05 20:24 UTC
Requires
- php: >=7.0
- gabordemooij/redbean: >=5.3
- loandbeholdru/shorts: *
- robinvdvleuten/ulid: >=3.0
- slim/slim: >=3.1
This package is auto-updated.
Last update: 2025-10-29 03:32:44 UTC
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.