lark/app
最新稳定版本:0.25.0
Composer 安装命令:
composer create-project lark/app
包简介
Lark Application
关键字:
README 文档
README
Lark is a modern, lightweight app framework designed specifically for developing REST APIs.
Installation
Create project directory and move to the project directory:
mkdir myapp
cd myapp
Install using composer:
composer create-project lark/app ./
Then, initialize project:
./lark --init
Console
Lark Console is available to assist in creating routes, schemas, models and revisions. Lark Console can be run from the project root directory.
./lark route items
Namespaces can also be used.
./lark route api/items
View all commands with
./larkor./lark helpView command specific help with./lark help COMMAND
Middleware
Create middleware files in the app/Middleware directory.
Example middleware class:
namespace App\Middleware; use Lark\Request; use Lark\Response; class UserMiddleware { public function auth(Request $req, Response $res): void { // auth here } }
For this example, the middleware can be setup in app/routes.php like:
router()->matched([App\Middleware\UserMiddleware::class, "auth"]);
Read the framework docs on middleware.
App Class
#todo docs about app class props + methods
MVC Application
Lark can use controllers that are common in MVC applications. Create controller files in the app/Controller directory and extend the base App\Controller class.
Example base controller class app/Controller.php:
namespace App; use Lark\Response; abstract class Controller { protected Response $res; public function __construct() { $this->res = res(); } }
Example controller class app/Controller/ItemsController.php:
namespace App\Controller; use App\Model\Item as ItemModel; class ItemsController extends \App\Controller { private ItemModel $model; public function __construct() { $this->model = new ItemModel; } public function get(): void { $this->res->json( $this->model->find() ); } }
For this example, a route can be setup in app/routes.php like:
router()->get("/items", [App\Controller\ItemsController::class, "get"]);
Read the framework docs on route actions.
Custom Validation Rules
Custom validation rules should be created in the app/Validator directory like app/Validator/MyRule.php.
Read the framework docs on custom validation rules.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-27