elvislakota/router

Fast routing built with FastRoute.

dev-master / 1.0.x-dev 2019-01-13 01:42 UTC

This package is not auto-updated.

Last update: 2024-03-22 00:34:17 UTC


README

Author

This package is compliant with PSR-7. If you notice compliance oversights, please send a patch via pull request.

Install

Via Composer

$ composer require elvislakota/router:dev-master

Requirements

The following versions of PHP are supported by this version.

  • PHP 7.1
  • PHP 7.2

Usage

Here's a basic usage example:

.htaccess

Create a .htaccess file in your htdocs folder

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) public/ [L]

</ifModule>


Then create a new Folder 'public' in your htdocs folder and add index.php with content

<?php

require '../vendor/autoload.php';

//Your middleware class
$middlewareTest = new \elvislakota\Router\example\MiddlewareTest();

//Custom error messages for the error 404,405 and middleware
$exceptionTest = new \elvislakota\Router\example\ExceptionTest();

//Router
$router = new \elvislakota\Router\Router($exceptionTest);

//Add a route
$router->addRoute(\elvislakota\Router\Router\Route::getRoute('GET','/',
    'elvislakota\Router\example\ControllerTest::helloWorld', $middlewareTest));

//Dispatch and emit data
$serverResponse = $router->dispatch();
$router->emit();

Testing

$ vendor/bin/phpunit

Contributing

Contributions are welcome and will be fully credited.

We accept contributions via Pull Requests on Github.

Credits

License

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