承接 fremail/lumen-nested-route-groups 相关项目开发

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

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

fremail/lumen-nested-route-groups

最新稳定版本:1.1.0

Composer 安装命令:

composer require fremail/lumen-nested-route-groups

包简介

Extends a lumen application for using nested route groups. In addition to the groups it's possible to use any() and match() methods.

README 文档

README

v.1.1.0 Add $app->any() and $app->match() methods (no breaking changes)

Lumen nested route groups

Extends a lumen application for using nested route groups. Lumen already uses a group in bootstrap/app.php, that is why you can't use another groups in app/Http/routes.php. This lib removes the restriction.

How to install (steps)

1. Install using Composer

composer require "fremail/lumen-nested-route-groups:~1.1"

2. Required changes in bootstrap/app.php

Change initialization of Lumen Application class to initialization of Lumen Nested Route Groups Application class in bootstrap/app.php.

Before:

$app = new Laravel\Lumen\Application(
    realpath(__DIR__.'/../')
);

After:

$app = new Fremail\NestedRouteGroups\Application(
    realpath(__DIR__.'/../')
);

After these simple steps you can use nested route groups in your application!

Additional namespaces configuration

By default this lib uses nested namespace (Laravel style), but you can determine to use full namespaces instead (Lumen style).

Steps for using full namespaces:

  1. Create config directory if you don't have one in the project root.

  2. Copy NestedRouteGroups.php from vendor/fremail/lumen-nested-route-groups/config folder to the created config dir in the root.

  3. Open the config/NestedRouteGroups.php file and set 'namespace' value to 'full'.

  4. Add this line to your bootstrap/app.php: $app->configure('NestedRouteGroups');

Any() and Match() methods

Do you like any() and match() methods on Laravel? I love them! That's why I added supporting them on Lumen. The syntax is the same as for Laravel:

$app->match($methods, $uri, $action);

Where $methods - an array of methods. Example: ['get', 'post', 'delete']. $uri and $action are the same as on other methods

$app->any($uri, $action);

Here are $uri and $method are the same as on other methods like $app->get(...) etc.

Example of using this lib

This is an example of app/Http/routes.php

$app->group(['middleware' => 'auth'], function () use ($app) {

    $app->get('test', function () {
        echo "Hello world!";
    });

    $app->group(['prefix' => 'user'], function () use ($app) {
        $app->get('{id}', 'UserController@show');
        $app->post('/', 'UserController@store');
        $app->delete('{id}', 'UserController@destroy');
    });

    /**
     * only admins
     */
    $app->group(['middleware' => 'admin'], function () use ($app) {

        $app->group(['prefix' => 'admin'], function () use ($app) {
            $app->get('/', 'AdminController@index');
        });

    });
    
    /**
     * $app->any and $app->match available from v1.1.0
     */
    $app->any('/', function () use ($app) {
        echo "Hey! I don't care it's POST, GET, PATCH or another method. I'll answer on any of them :)";
    });
    
    $app->match(['PATCH', 'PUT', 'DELETE'], '/old/', function () use ($app) {
        echo "This is an old part of our site without supporting REST. Please use only GET and POST here.";
    });

});

统计信息

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

GitHub 信息

  • Stars: 15
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

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