benson/route-me 问题修复 & 功能扩展

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

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

benson/route-me

Composer 安装命令:

composer require benson/route-me

包简介

A basic router for REST APIs with all compatible with all RESTFUL verbs

README 文档

README

Description

Route-Me is a lightweight and flexible PHP router package for creating RESTful APIs. It supports route parameters, middleware, and PSR-7 request/response handling. Route-Me is built using the PSR-7 HTTP message interfaces and can be used with any PSR-7 implementation. It is also framework-agnostic and can be used with any PHP framework or standalone application. Route-Me is developed and maintained by Benson Osei-Mensah.

Installation

To install Route-Me, run the following command in your project directory:

composer require benson/router-me

Table of Contents

Features

  • Route Definition: Add routes to the router using the addRoute() method.
  • Middleware: Apply middleware functions to specific routes or globally using the withMiddleware() method.
  • Request Handling: Handle incoming requests by matching URL and HTTP method against defined routes.
  • Error Handling: Handle 404 Not Found scenarios and custom error handling logic.
  • Route Parameters: Support for route parameters defined within the URL pattern.
  • Flexible Callbacks: Use closures or class methods as callback functions.
  • PSR-7 Support: Built-in support for JSON request/response handling.

Usage

To use Route-Me in your project, follow these steps:

  1. Import the composer autoloader into your PHP file:

    require_once 'vendor/autoload.php';
  2. Create a new instance of the Router class:

    $router = new Router();
  3. Add routes to the router using the addRoute() method:

    $router->get('/users', function () {
        // Handle GET request to /users
    });
    
    // Add class method as callback
    $router->addRoute('GET', '/users', "App\Controllers\UserController@index");
    
    // Add route parameters
    $router->addRoute('GET', '/users/{id}', function ($id) {
        // Handle GET request to /users/{id}
    });
    
    // Add middleware
    $router->addRoute(
        'GET', // HTTP method
        '/user/{id}', // URL pattern
        'App\Controllers\UserController@show', // Callback function
        'App\Middleware\Authenticate@handle' // Middleware function
        );
    
        // Add middleware to all routes
        $router->withMiddleware('App\Middleware\Authenticate@handle');
    
    $router->post('/users', function () {
        // Handle POST request to /users
    });
  4. Handle incoming requests by calling the run() method:

    $router->run(); 

Contribution

Contributions are welcome! To contribute to Route-Me, follow these steps:

  1. Fork the repository.

  2. Create a new branch.

    git checkout -b your-branch-name
  3. Make your changes.

  4. Commit your changes and push them to your branch. Make sure to add a clear commit message and include any relevant documentation updates. Since Route-Me follows the PSR-2 coding standards, please ensure that your code adheres to these standards. If you are not sure, you can use the PHP Coding Standards Fixer

    git add .
    git commit -m "your commit message"
    git push origin your-branch-name
  5. Submit a pull request. Please ensure that you adhere to the coding standards and write clear commit messages.

License

Route-Me is open-source software released under the MIT License. See LICENSE for details.

Author

Route-Me is developed and maintained by Benson Ose-Mensah.

benson/route-me 适用场景与选型建议

benson/route-me 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-19