falgunphp/routing

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

This package is auto-updated.

Last update: 2024-05-27 02:34:27 UTC


README

Simple Routing Library.

Install

Please note that PHP 7.4 or higher is required.

Via Composer

$ composer require falgunphp/routing

Usage

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

$router = new Router('http://localhost/');

$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);

License

The MIT License (MIT). Please see License File for more information.