适用于Luminar框架的一个轻量级和灵活的路由器

dev-main 2024-09-23 13:57 UTC

This package is auto-updated.

Last update: 2024-09-23 13:58:03 UTC


README

Tests Status

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组件的概述。它涵盖了安装、基本路由等内容。