anonym-php/anonym-route 问题修复 & 功能扩展

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

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

anonym-php/anonym-route

Composer 安装命令:

composer require anonym-php/anonym-route

包简介

AnonymFramework Route Component

README 文档

README

#Anonym-Route

This is a route component for AnoynmFramework.

Launch the component

include 'vendor/autoload.php';
use Anonym\Components\Route\RouteCollector;
use Anonym\Components\Route\Router;
use Anonym\Components\HttpClient\Request;
$collector = new RouteCollector();

How can i add a new route?

$collector->get('uri', ['_controller' => 'Controller:method',
                        'access' => [
                         'role' => '',
                         'next' => null,
                         'name' => 'name',
                         ]]);

Which types are supported?

GET, POST, HEAD, PUT, OPTIONS, DELETE, PATCH

How to run?

use Anonym\Components\Route\Router;

$router = new Router( new Request());
$router->run();

How can i add a middleware?

$collector->get('/', ['_middleware' => ['name' => 'middlewarename', 'role' => 'aaa', 'next' => function(){}]]);

How can i add a middleware in a controller?

public function __construct(){
  $this->middleware('middlewarename');
}

How can i create a Controller

add it to composer.json

"Anonym\Controllers": "path"

and create controller in the "path"

use Anonym\Components\Route\Controller;

class Test extends Controller{

   // do nothing

}
$collector->get('/{test}', 'Controller:method'); // {test} is required
$collector->get('/{test!}', 'Controller:method'); // {test!} is required
$collector->get('/{test?}', 'Controller:method'); // {test?} is optional

How can I set the namespace?

$router = new Router()->setNamespace('Your\Namespace');

// or 

$collector->get('/', ['_controller' => 'Test:method', '_namespace' => 'Your\Namespace']);

统计信息

  • 总下载量: 142
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-17