定制 gobline/router 二次开发

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

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

gobline/router

Composer 安装命令:

composer require gobline/router

包简介

Router component

README 文档

README

The purpose of routing is to map a URL to an array of data or to a callback, allowing to route the request to the correct resource. In an MVC context, this is typically a controller and a controller action.

There are two routers bundled by default:

  • Gobline\Router\LiteralRoute (with its i18n friend Gobline\Router\I18n\LiteralRoute)
  • Gobline\Router\PlaceHolderRoute (with its i18n friend Gobline\Router\I18n\PlaceHolderRoute)

The Router component allows to have your URLs translated in multiple languages, allowing to have more SEO- and user-friendly URLs.

LiteralRoute

The Literal route is for doing exact matching of the URI path.

$router = (new Gobline\Router\LiteralRoute('/user/profile')) // profile is the route name and /user/profile is the route to match
    ->setName('profile')
    ->values([
        'controller' => 'user',
        'action' => 'profile',
    ]);

I18n LiteralRoute

$router = (new Gobline\Router\LiteralRoute('/user/profile'))
    ->setName('profile')
    ->values([
        'controller' => 'user',
        'action' => 'profile',
    ])
    ->i18n([
        'fr' => '/membre/profil',
        'nl' => '/gebruiker/profiel',
    ]);

PlaceHolderRouter

$router = (new Gobline\Router\PlaceHolderRoute('/user/:id(/)(/articles/:action(/))'))
    ->setName('profile')
    ->values([
        'controller' => 'articles',
        'action' => 'list',
    ])
    ->constraints([
        'id' => '[0-9]+',
        'action' => '[a-zA-Z]+',
    ]);

I18n PlaceHolderRouter

$router = (new Gobline\Router\PlaceHolderRoute('/user/:id(/)(/articles/:action(/))'))
    ->setName('profile')
    ->values([
        'controller' => 'articles',
        'action' => 'list',
    ])
    ->constraints([
        'id' => '[0-9]+',
        'action' => '[a-zA-Z]+',
    ])
    ->i18n([
        'fr' => '/membre/:id(/)(/articles/:action(/))',
        'nl' => '/gebruiker/:id(/)(/artikelen/:action(/))',
        'placeholders' => [
            'action' => [
                'fr' => [
                    'list' => 'liste',
                ],
                'nl' => [
                    'list' => 'lijst',
                ],
            ],
        ],
    ]);

Matching a URL to a Collection of Routes

$routeCollection = new Gobline\Router\RouteCollection();
$routeCollection
    ->get(new Gobline\Router\LiteralRoute(/*...*/))
    ->post(new Gobline\Router\PlaceHolderRouter(/*...*/));

$requestMatcher = new Gobline\Router\RequestMatcher($routeCollection);
$routeData = $requestMatcher->match($request); // psr-7 server request

Generating a URL Based on Route Data

$uriBuilder = new Gobline\Router\UriBuilder($routerCollection);

$url = $uriBuilder->makeUrl(new Gobline\Router\RouteData('profile', ['id' => 42]));

Installation

You can install the Router component using the dependency management tool Composer. Run the require command to resolve and download the dependencies:

composer require gobline/router

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-12-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固