Skip to content

DO NOT USE THAT IN PRODUCTION. IT'S PURE YOLO CODE.

License

Notifications You must be signed in to change notification settings

pimolo/SimpleRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleRouter

Installation

$ composer require pimolo/simple-router

Usage

<?php

use Pimolo\SimpleRouter\Router;
use Pimolo\SimpleRouter\DTO\Route;
use Symfony\Component\HttpFoundation\Request;

require_once 'vendor/autoload.php';

// Wrap the request with HttpFoundation
$request = Request::createFromGlobals();

$kernel = new Router();

// Defines routes

$home = (new Route('/home', ['GET'], function () {
    return 'Welcome to my app';
}
));

$login = (new Route('/login', ['GET', 'POST'], function () {
    return 'Please login';
}
));

// Handle the resource
echo $kernel->route($request, [$home, $login]);

And if you want to test it :

$ php -S localhost:8000 main.php

About

DO NOT USE THAT IN PRODUCTION. IT'S PURE YOLO CODE.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages