定制 eightyfive/laravel-autoroute 二次开发

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

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

eightyfive/laravel-autoroute

最新稳定版本:v3.0.0-alpha.20

Composer 安装命令:

composer require eightyfive/laravel-autoroute

包简介

Laravel YAML routes

README 文档

README

Autoroute helps you register Laravel routes as YAML.

"La route? Là où on va, on a pas besoin... De route."

Install

composer require eyf/laravel-autoroute

Usage

<?php
// app/Providers/RouteServiceProvider.php

use Eyf\Autoroute\Autoroute;

class RouteServiceProvider extends ServiceProvider
{
    public function map(Autoroute $autoroute)
    {
        $autoroute->load(["api.yaml"]);
    }
}

Note: It will automatically look for files inside the Laravel routes/ folder.

Sample api.yaml

domain: api.example.org
prefix: v1
middleware:
    - api
namespace: App\Http\Controllers\Api
paths:
    "users":
        get:
            uses: UserController@index

        post:
            uses: UserController@store

    "users/{id}":
        get:
            uses: UserController@find

        put:
            uses: UserController@update

Or using the compact syntax:

domain: api.example.org
prefix: v1
middleware:
    - api
namespace: App\Http\Controllers\Api
paths:
    "users":
        get: user.index
        post: user.store

    "users/{id}":
        get: user.find
        put: user.update

Template parameters

Autoroute supports light parameters in YAML files. The format is %<parameter_name>%.

For instance let's say you need to work with a local API subdomain:

<?php
// app/Providers/RouteServiceProvider.php

use Eyf\Autoroute\Autoroute;

class RouteServiceProvider extends ServiceProvider
{
    public function map(Autoroute $autoroute)
    {
        $parameters = [
            "app_domain" => env("APP_DOMAIN", "example.org"),
        ];

        $autoroute->load(["api.yaml"], $parameters);
    }
}

And in your local .env file:

APP_DOMAIN=localhost:8000
# APP_DOMAIN=example.org # PROD

And in your api.yaml file:

domain: api.%app_domain%
prefix: v1
# ...

Default route names

If you don't provide an as option in your route definition:

"users/{id}":
    get:
      uses: UserController@find
        as: my_user_find_route_name

Autoroute will generate a default route name based on the current namespace, controller and action names:

"users/{id}":
    get:
        uses: UserController@find
        # as: api.user.find (generated)

Custom default route name

If you're not happy with the default route name format, you can implement your own Eyf\Autoroute\RouteNamerInterface and bind it accordingly in your Laravel app service provider:

<?php
// app/Providers/AppServiceProvider.php

use Eyf\Autoroute\RouteNamerInterface;
use App\Services\MyRouteNamer;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind(RouteNamerInterface::class, MyRouteNamer::class);
    }
}

uses compact syntax

If you're not using any route options (as, etc...), you can use a "compact" syntax to specify your controllers:

domain: api.%app_domain%
prefix: v1
middleware:
    - api
namespace: App\Http\Controllers\Api
paths:
    "users":
        get: user.index
        post: user.store

    "users/{id}":
        get: user.find
        put: user.update

Custom compact syntax

You can customize the shorthand syntax by implementing RouteNamerInterface::getUses(string $compact).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固