承接 artisangang/router 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

artisangang/router

Composer 安装命令:

composer require artisangang/router

包简介

Fast and simple request router for PHP7

README 文档

README

Install

To install with composer:

composer require artisangang/router

Requires PHP 7.

Usage

<?php

require '/path/to/vendor/autoload.php';

// storage for locked routes
$storage = new \Router\FileStorage(__DIR__);

$routeManager = new \Router\Manager;
$routeManager->storage( $storage );

// lock routes in production mode for performance
$routeManager->lock();

if (isset($_ENV["development"])) {
    $routeManager->unlock();
}

//product routes
$p = $routeManager->router();
$p->use('GET /product/', 'IndexController@productIndex');
$p->use('GET /product/:id', 'IndexController@productSingle');
$p->use('POST /product', 'IndexController.productCreate');
$p->use('PUT /product/:id', 'IndexController.productUpdate');
$p->use('PATCH /product/:id', 'IndexController.productPatch');
$p->use('DELETE /product/:id', 'IndexController.productDelete');

// category routes
$c = $routeManager->router();
$c->use('GET /category', 'IndexController.categoryIndex');
$c->use('POST /category', 'IndexController.categoryCreate');
$c->use('PUT /category/:id', 'IndexController.categoryUpdate');
$c->use('PATCH /category/:id', 'IndexController.categoryPatch');
$c->use('DELETE /category/:id', 'IndexController.categoryDelete');

// shop routes
$c->get('/shop', 'IndexController.shopIndex');
$c->post('/shop', 'IndexController.shopCreate');
$c->put('/shop/:id', 'IndexController.shopUpdate');
$c->patch('/shop/:id', 'IndexController.shopPatch');
$c->delete('/shop/:id', 'deleteShop');

// group routes in v1 prefix
$r = $routeManager->router('v1');
// add routes to group
$r->child($p, $c);

// create another group with prefic api
$a = $routeManager->router('api');
// add route to this gorup
$a->child($r);

// find route match based on current request uri, this will return Router\Commands\HttpCommand instance if match found
$request = $routeManager->match($a);

if (!$request) {
    die('404,Page not found!');
}

// extract params from uri
// for example with uri /product/1 matched with pattern /product/:id will return ['id' => 1]
$params = $request->params($routeManager->requestUri);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固