This is a lightweight framework designed for fast development of restful interfaces. If you are like me, tired of using the traditional MVC framework to write a microservices or a front-end decoupled API interface, can not stand for a simple interface to do a lot of redundant coding (and ctrl-c/ctrl-v), then, you will love this framework!
Give me a chestnut first.
1, write a helloworld.php, put in the framework specified directory (by default, and index.php sibling apis/directory)
/** * @path ("/HW") */class helloworld{ /** * @route ({"GET", "/"}) */public function dosomething () { return "Hello world!"; }}
2. Browser input http://your-domain/hw/
You will see: Hello world! is so simple, no additional configuration is required, no inheritance is required, and no combination is required.
What happened
Looking back at helloworld.php, the special place is the annotation (@path, @route), yes, the framework obtains the routing information and the binding input and output through annotations. But don't worry about performance, comments will only parse once after the class file has been modified. More @ comments are explained later.
Let's look at a more specific example.
This is an example of a login interface
/** * User Rights verification * @path ("/tokens/") */class tokens{/** * Login * Authorized by username password * @rou Te ({"POST", "/accounts/"}) * @param ({"Account", "$._post.account"}) Username * @param ({"Password", "$._post.password"}) password * * @throws ({"Invalidpassword", "res", "403 Forbidden", {"error": "Invalidpassword"}}) the username or password is invalid * * @return ({"Bo Dy "}) * return token, same as token in cookie, * {" token ":" XXX "," uid "=" XXX "} * * @return ({" Cookie "," token "," $token "," +365 Days ","/"}) returns the token * @return ({" Cookie "," UID "," $uid "," +365 Days ","/"}) through a cookie to return the UID */Public Function creat Etokenbyaccounts ($account, $password, & $token,& $uid) {//verify user $uid = $this->users->verifypassword ($acco UNT, $password); Verify::istrue ($uid, New Invalidpassword ($account)); $token = ...; return [' token ' = $token, ' uid ' = ' $uid]; }/** * @property ({"Default": "@Users"}) dependent properties, injected by framework * @var Users */public $users;}
What else can I do?
- Dependency management (Dependency injection),
- Auto-output interface documentation (not Doxgen class, method document, but document describing HTTP interface)
- Interface Cache
- Hook
Accessing the database with Ezsql
Ezsql is a simple object-oriented SQL build tool that provides simple basic SQL operations.
Interface
/** @path (/myclass) */class myclass{ /** * @route ({"GET", "/do"}) * @param ({"arg0", "$._get.arg0"}) */Public dosomething ($arg 0) { return sql::select (' xxx ')->from (' table_xxx ')->where (' xxx =? '), $arg 0)->get ($this->db); } /** * Dependency Injection PDO Instance * @property * @var PDO */public $db;}
Configuration file
{ " MyClass": {" properties": { "db": "@db1"} }, }, "DB1": { "singleton": True, "class": "PDO", "pass_by_construct": True, "Properties": { "DSN": "mysql:host=127.0.0.1; Dbname=xxx ", " username ":" xxxx ", " passwd ":" xxxx " } },}
The above is the whole content of this article, I hope that everyone's study has helped.