lozitskiys/verse 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2018-12-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固