olliecodes/laravel-route-registrars 问题修复 & 功能扩展

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

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

olliecodes/laravel-route-registrars

Composer 安装命令:

composer require olliecodes/laravel-route-registrars

包简介

Adds route registrars as an alternative object based approach to registering routes.

README 文档

README

A Laravel package that introduces a clean object based alternative to Laravel route files.

Packagist Version Packagist PHP Version Support GitHub codecov

Laravel Route Registrars

This package introduces a clean object based way to define your routes in a Laravel application. A tutorial on the basic premise exists on Laravel news, written by @juststeveking.

Install

Install via composer.

$ composer require olliecodes/laravel-route-registrars

Fresh Laravel Installation

If you're installing this package on a fresh laravel installation, you'll want to run the following command before you do anything with your routes.

php artisan init:routing

This will overwrite the app/Providers/RouteServiceProvider.php file with one compatible with the route registrars, and create default route registrars to replace both routes/web.php and routes/api.php.

Existing Laravel Installation

If you have an existing application, it is recommended that you read through the Laravel News article that covers this approach, as you're going to have to manually refactor your route service provider and route files.

Requirements

This package requires the following;

  • PHP >= 8.0 (Including 8).
  • laravel/framework >= 9.0

Usage

To register new routes, you can either add their definitions to the map method of a RouteRegistrar, or create a new one.

Creating a new registrar

The following command will create a new registrar inside app/Http/Routes.

php artisan make:registrar {name}

The {name} can be any valid class name, or sub-namespace. For example, using Auth\\GuestRoutes will create app/Http/Routes/Auth/GuestRoutes.php.

There are several options available when creating a registrar.

--C|hasChildren

Create a route registrar that has the MapRouteRegistrars trait so that it can map child registrars.

--W|web

Create the route registrar in app/Http/Routes/Web, an option left in for those of you that are splitting the Web and API routes.

--A|API

Exactly the same as the above option, except it creates it in app/Http/Routes/Api,

Registering Registrars

Any class that wants to register registrars can use the following trait.

OllieCodes\Registrars\Concerns\MapsRouteRegistrars

Once doing so, there are three ways to register. All of them require an instance of the following class.

Illuminate\Contracts\Routing\Registrar

This interface is implemented by the Laravel Router class, so you can use that.

Register multiple

Call the following method with an instance of the laravel router, and an array of fully qualified class names for the registrars.

mapRouteRegistrars(Registrar $router, array $registrars)

Register one

Call the following method with an instance of the laravel router, and the fully qualified class name of the registrars.

mapRouteRegistrar(Registrar $router, string $registrar)

Register from paths

Call the following method with an instance of the laravel router, and an array of paths where the registrars are held.

This method will use the order that the files are returned, so please keep route order precedence in mind.

loadRouteRegistrars(Registrar $router, array $paths)

olliecodes/laravel-route-registrars 适用场景与选型建议

olliecodes/laravel-route-registrars 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.08k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2022 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 olliecodes/laravel-route-registrars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 olliecodes/laravel-route-registrars 我们能提供哪些服务?
定制开发 / 二次开发

基于 olliecodes/laravel-route-registrars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-07