codeinc / psr15-router-middleware
This package is abandoned and no longer maintained.
The author suggests using the codeinc/router package instead.
A PSR-15 router middleware
2.0.2
2018-08-30 06:53 UTC
Requires
- php: >=7.1
- codeinc/psr7-responses: ^1.3
- psr/http-message: ^1.0
- psr/http-server-handler: ^1.0
- psr/http-server-middleware: ^1.0
Requires (Dev)
Suggests
- codeinc/middleware-dispatcher: PSR-15 middleware dispatcher
This package is not auto-updated.
Last update: 2022-02-01 13:13:51 UTC
README
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).