承接 gacela-project/router 相关项目开发

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

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

gacela-project/router

Composer 安装命令:

composer require gacela-project/router

包简介

A minimalistic HTTP router.

README 文档

README

A minimalistic HTTP router, ideal for your proof-of-concept projects and decoupled controllers.

GitHub Build Status Scrutinizer Code Quality Scrutinizer Code Coverage Psalm Type-coverage Status Mutation testing badge MIT Software License

Why?

There are many other routers out there. Eg: using Symfony Framework, Laravel, etc... however, these are really rich in features which means they add a lot of accidental complexity and dependencies to your vendor, that you might want to avoid. At least for your proof-of-concept project.

Gacela Router doesn't aim to be the best router that can do everything, but a light router to have the bare minimum code, ideal for your simple ideas to emerge.

For a POC, we value simplicity over a rich-feature library.

Installation

composer require gacela-project/router

Example

# Request only the parameters you need: Routes, Bindings, Handlers, Middlewares
# All except Routes are optional, and you can place them in any order.

$router = new Router(function (Routes $routes, Bindings $bindings, Handlers $handlers, Middlewares $middlewares) {

    // Custom redirections
    $routes->redirect('docs', 'https://gacela-project.com/');
    
    // Matching a route coming from a particular or any custom HTTP methods
    $routes->get('custom', CustomController::class, '__invoke');
    $routes->...('custom', CustomController::class, 'customAction');
    $routes->any('custom', CustomController::class);

    // Matching a route coming from multiple HTTP methods
    $routes->match(['GET', 'POST'], '/', CustomController::class);
    
    // Binding custom dependencies on your controllers
    $routes->get('custom/{number}', CustomControllerWithDependencies::class, 'customAction');
    $bindings->bind(SomeDependencyInterface::class, SomeDependencyConcrete::class)

    // Handle custom Exceptions with class-string|callable
    $handlers->handle(NotFound404Exception::class, NotFound404ExceptionHandler::class);

    // Apply middleware to all routes
    $middlewares->add(new GlobalMiddleware());

    // Use individual middleware to a route
    $routes->get('admin', AdminController::class)->middleware(new AuthMiddleware());

    // Or define a middleware group
    $middlewares->group('web', [
        new SessionMiddleware(),
        new CsrfMiddleware(),
    ]);

    // And apply the group to the route
    $routes->get('/', Controller::class)->middleware('web');

});

$router->run();

Working demo

For a working example run composer serve and check the example/example.php

TIP: composer serve is equivalent to:

php -S localhost:8081 example/example.php

gacela-project/router 适用场景与选型建议

gacela-project/router 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.22k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2023 年 04 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 gacela-project/router 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 17
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-09