luminar-organization / router
适用于Luminar框架的一个轻量级和灵活的路由器
dev-main
2024-09-23 13:57 UTC
Requires
- php: >=8.2
- luminar-organization/core: dev-main
- luminar-organization/http: dev-main
Requires (Dev)
- phpunit/phpunit: >=11.3.1
This package is auto-updated.
Last update: 2024-09-23 13:58:03 UTC
README
Luminar路由器是Luminar PHP框架的一个轻量级路由组件。它允许您在应用程序中定义和管理路由,支持依赖注入和高级路由处理。
安装
通过Composer安装
composer require luminar-organization/router
基本用法
定义路由
您可以使用Route注解来定义路由,指定HTTP方法和路由模式。
namespace App\Controllers; use Luminar\Http\Controller\AbstractController; use Luminar\Http\Response; class ExampleController extends AbstractController { public static string $response = "Hello World"; #[Route("/example", methods: "GET")] public function index(): Response { return $this->text($this::$response); } }
处理请求
要处理传入的HTTP请求,请使用dispatch
方法
$response = $router->dispatch($_SERVER["REQUEST_METHOD"], $_SERVER["REQUEST_URI"]);
许可
本软件包是开源软件,许可协议为MIT许可证
本README提供了如何在使用项目中的luminar-organization/router
组件的概述。它涵盖了安装、基本路由等内容。