falgunphp/routing

dev-master 2021-06-26 19:56 UTC

This package is auto-updated.

Last update: 2024-09-27 03:24:43 UTC


README

简单路由库。

安装

请注意,需要PHP 7.4或更高版本。

通过Composer

$ composer require falgunphp/routing

用法

<?php
use Falgun\Routing\Router;
use Falgun\Routing\RequestContext;

$router = new Router('https:///');

$router->any('/')->action(HomeController::class, 'index');
$router->get('/test')->action(TestController::class, 'index');


// Fetch method and URI from somewhere
$httpMethod = $_SERVER['REQUEST_METHOD'];
$uri = $_SERVER['REQUEST_URI'];

// create request context
$requestContext = new RequestContext($uri, $httpMethod);

/* @var $route RouteInterface */
$route = $this->router->dispatch($requestContext);

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件