PHP Classes

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

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 37 All time: 10,955 This week: 455Up
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: 24 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 226511 in Nigeria Nigeria
Week rank: 178 Up7 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 9x

Documentation

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 (10)  
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 (10)  /  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 (10)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:37
This week:0
All time:10,955
This week:455Up