2017 © Pedro PelĂĄez
 

library psr15-router-middleware

A PSR-15 router middleware

image

codeinc/psr15-router-middleware

A PSR-15 router middleware

  • Friday, July 27, 2018
  • by joanfabregat
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

PSR-15 router middleware

This library is a very simple PSR-15 controller router middleware written in PHP 7.1., (*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("

Hello world!

"); } } class AnotherPage extends AbstractController { public static function getUriPath():string { return '/another-page.html'; } public function process():ResponseInterface { return new HtmlResponse("

Another page

"); } } class NotFound extends AbstractController { public static function getUriPath():string { return '/error404.html'; } public function process():ResponseInterface { return new HtmlResponse("

Page not found

"); } } $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:, (*2)

composer require codeinc/psr15-router-middleware

License

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

The Versions