This repository has been archived by the owner. It is now read-only.
A PSR-15 router middleware
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README.md
composer.json

README.md

PSR-15 router middleware

This library is a very simple PSR-15 controller router middleware written in PHP 7.1.

Usage

<?php
use CodeInc\Psr15RouterMiddleware\RouterMiddleware;
use CodeInc\Psr15RouterMiddleware\AbstractController;
use CodeInc\Psr7Responses\HtmlResponse;
use Psr\Http\Message\ResponseInterface;

class HomePage extends AbstractController 
{
    public static function getUriPath():string { return '/'; }   
    public function process():ResponseInterface { return new HtmlResponse("<h1>Hello world!</h1>"); }
}
class AnotherPage extends AbstractController
{
    public static function getUriPath():string { return '/another-page.html'; }   
    public function process():ResponseInterface { return new HtmlResponse("<h1>Another page</h1>"); }
}
class NotFound extends AbstractController
{
    public static function getUriPath():string { return '/error404.html'; }   
    public function process():ResponseInterface { return new HtmlResponse("<h1>Page not found</h1>"); }
}

$router = new RouterMiddleware();
$router->registerControllerClass(HomePage::class);
$router->registerControllerClass(AnotherPage::class);
$router->setNotFoundControllerClass(NotFound::class);

Installation

This library is available through Packagist and can be installed using Composer:

composer require codeinc/psr15-router-middleware

License

This library is published under the MIT license (see the LICENSE file).