lozitskiys/verse
Composer 安装命令:
composer require lozitskiys/verse
包简介
Decorator based nano PHP framework
关键字:
README 文档
README
Example of index.php:
<?php /** @var \Verse\Env $env */ $env = require_once __DIR__ . '/../env.php'; $user = new CurrentUser($env->pdo()); $app = // App decorator new AppLocaleAndTz( // App decorator new AppSession( // Base App implementation new AppBase() ) ); $action = // Action decorator new ActionAuthorized( // Base Action implementation new NumbersListJson(), new GuestAccessLvl() ); $app->start($action, $env, $user);
Verse uses Action Domain Responder pattern. Example of simple action:
<?php namespace Actions; class NumbersListJson implements Action { public function run(Env $env, User $user): Response { return new RespJson([ 'result' => 'ok', 'list' => [1, 2, 3, 4] ]); } }
Routing
Routes are stored in yaml file, for example:
/auth: Auth/AuthForm /auth/process POST: Auth/AuthProcess
Each line which starts from "/" is a separate route. Default HTTP method is GET. You can define route like this:
/auth: Auth/AuthForm
or like that:
/auth GET: Auth/AuthForm
You can use tokens to retrieve variables from URI:
/blog/read/{id}: Blog/ReadPost
or even
/blog/list/{tag}/{author}: Blog/ListPosts
Use tokens in action:
class ListPosts implements Action { public function run(Env $env, User $user): Response { $tag = $env->route()->token('tag'); $author = $env->route()->token('author'); return new Response\RespHtml($env->tpl()->render( 'blog/list', [ 'posts' => (new BlogPosts($tag, $author))->list(), 'tag' => $tag, 'author' => $author ] )); } }
TBA
统计信息
- 总下载量: 163
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2018-12-21