定制 lark/app 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 ./lark or ./lark help View 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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固