emma/http-manager 问题修复 & 功能扩展

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

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

emma/http-manager

Composer 安装命令:

composer require emma/http-manager

包简介

A PHP 8.0+ Attributes Based HTTP Routing. Can be used for all cases, MVC and Middleware - Class/Method/Function

README 文档

README

php 8 Attributes based Http Routing. Can be used for all cases, MVC and Middleware - Class/Method/Function

QUICK HOW TO:

===================

<?php

include dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . "autoloader.php"; //composer autoloader

// <!-- Controller Class file -->
use Emma\Http\Mappings\RequestMapping;
use Emma\Http\Mappings\PostMapping;
use Emma\Http\Mappings\GetMapping;
use Emma\Http\Request\Method;

#[RequestMapping(routes: '/index', httpRequestMethod: [Method::POST, Method::GET])]
class IndexController
{

    /**
     *   Full Routing to this method is: '/index/login' -> Class level routing plus the method level
     *   Class Method can only be accessed via HTTP - POST
     */
    #[PostMapping('/login')] 
    public function login()
    {

    }

    /**
     * Class Method can be accessed via HTTP - POST and GET
     */ 
    #[RequestMapping('/logout', [Method::POST, Method::GET])]
    public function logout()
    {

    }

    /**
     * Class Method can be accessed via HTTP - GET
     * Auto-Map expected url parameter to the method
     */ 
    #[GetMapping('/count-trades/{status:[\w]+}')]
    public function countTradesByStatus(string $status)
    {

    }

    /**
    * Other Request Mapping Attributes exist....For example:
    *
    *   #[HeadMapping('/head-method-routing')]
    *   #[PutMapping('/upload')]
    *   #[PatchMapping('//summary/{id:[0-9]*}')]
    *   #[DeleteMapping('/delete-all')]
    *   #[OptionsMapping('/option/')]
    */

}

REGISTER ALL ROUTES HANDLERS USING THE SINGLETON - RouteRegistry.php

/**

 * 
 * @return array 
 * Register your Controllers, classes and/or Middleware and/or Functions here...

    use \Emma\Http\Mappings\PatchMapping;

    $routables = [
        IndexController::class,

        ...

        //example: Adding your function directly to the array.  

        #[PatchMapping('/update/summary/{id:[0-9]*}')]
        function middlewareQuickPatch(): void {
            $result = ['status' => true, 'data' => 'ABCD'];
            die(json_encode($result));
        },
    ];

    RouteRegistry::getInstance()->setRoutables($routables); //Register ALL

    

 *    ADVANCED USERS can have there arrays of functions and/or classes in different file and includes those file with array_merge()
 *    For Example:
 
    $routables = array_merge(
        (array) include "directory_to_array_file/class_file.php",
        (array) include "directory_to_array_file/direct_method_file.php",
        (array) include "directory_to_array_file/functions_file.php",
    );

    RouteRegistry::getInstance()->setRoutables($routables);  //Register ALL

* THEN, class_file.php:
* =====================
    return [
        IndexController::class,
        ...
    ];

    Other file will simply follow class_file example...
 */




// <!-- URL front entry point...Assuming you already setup your .htaccess as needed. 
// This service is independent of .htaccess. -->

YOU CAN REGISTER SINGLE ROUTABLE AT A TIME USING THE:

RouteRegistry::getInstance()->register($classOrFunctionOrObject);

Be sure to also have your .htaccess file well set as this package is framework agnostic.

Here is a sample .htaccess file:

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]

Let's test - index.php file inside the same folder as your .htaccess

<?php

$testHttpManager = new \Emma\Http\HttpManager();

try {
    $route = $testHttpManager->boot()->matchRequestRoutes();

    var_dump($route);

    /** Feel free to use https://github.com/debascoguy/Di For Autowiring(that is, Injecting) your classes/Methods/Function Dependencies... */

} catch (Exception $e) {

    die($e->getMessage());

}

** Feel free to use https://github.com/debascoguy/Di For Autowiring (that is, Inject) your classes/Methods/Function Dependencies...

emma/http-manager 适用场景与选型建议

emma/http-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 emma/http-manager 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 33
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2023-06-11