Quick Laravel Like PHP Router Library: Route HTTP requests to functions like Laravel

Recommend this page to a friend!
  Info   View files Documentation   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-10-30 (8 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 29 All time: 10,238 This week: 226Up
Version License PHP version Categories
quick-route 1.0The PHP License7.4HTTP, Design Patterns, PHP 7
Description Author

This package can route HTTP requests to functions like Laravel.

It can register routes that define URL patterns to be associated to class functions or closures that will be called when the current request URL matches those patterns.

The package can take the current HTTP request URI and method and dispatches to the registered functions.

Picture of Ahmad Mustapha
Name: Ahmad Mustapha <contact>
Classes: 12 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 294817 in Nigeria Nigeria
Week rank: 90 Up2 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 5x

Details

QuickRoute

An elegant http router built on top of FastRoute to provide more easy of use.

Information

Due to object-sharing between routes introduced in version 1, some errors cannot be fixed. <br/> Here is version 2, which is object-sharing free.

Installation

composer require ahmard/quick-route

Usage

Simple example

use QuickRoute\Route;
use QuickRoute\Route\Collector;
use QuickRoute\Route\Dispatcher;

require('vendor/autoload.php');

Route::get('/', function () {
    echo 'Hello world';
});

$method = $_SERVER['REQUEST_METHOD'];
$path = $_SERVER['REQUEST_URI'];
if (false !== $pos = strpos($path, '?')) {
    $uri = substr($path, 0, $pos);
}
$path = rawurldecode($path);


$collector = Collector::create()->collect()->register();

$dispatcher = Dispatcher::create($collector)->dispatch($method, $path);

switch (true) {
    case $dispatcher->isFound():
        $routeData = $dispatcher->getRoute();
        $routeData'controller');
        break;
    case $dispatcher->isNotFound():
        echo "Page not found";
        break;
    case $dispatcher->isMethodNotAllowed():
        echo "Request method not allowed";
        break;
}

Controller-like example

use QuickRoute\Route;

Route::get('/home', 'MainController@home');

Advance usage

use QuickRoute\Route;

Route::prefix('user')->name('user.')
    ->namespace('User')
    ->middleware('UserMiddleware')
    ->group(function (){
        Route::get('profile', 'UserController@profile');
        Route::put('update', 'UserController@update');
    });

Routes as configuration

//routes.php
use QuickRoute\Route;

Route::get('/', 'MainController@index');
Route::get('/help', 'MainController@help');


//server.php
use QuickRoute\Route\Collector;

$collector = Collector::create()
    ->collectFile('routes.php')
    ->register();

$routes = $collector->getCollectedRoutes();

Licence

QuickRoute is _MIT_ licenced.

  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageRoute (5 files)
  Plain text file Route.php Class Class source
  Plain text file RouteInterface.php Class Class source

  Files folder image Files  /  src  /  Route  
File Role Description
  Plain text file Collector.php Class Class source
  Plain text file Dispatcher.php Class Class source
  Plain text file DispatchResult.php Class Class source
  Plain text file RequestMethods.php Class Class source
  Plain text file TheRoute.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:29
This week:0
All time:10,238
This week:226Up

For more information send a message to info at phpclasses dot org.