2017 © Pedro Peláez
 

library titan-router

A simple and lightweight PHP router

image

tkaratug/titan-router

A simple and lightweight PHP router

  • Tuesday, November 14, 2017
  • by tkaratug
  • Repository
  • 1 Watchers
  • 2 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Titan Router

A simple and lightweight PHP router. Built by Turan Karatuğ (http://www.turankaratug.com), (*1)

Features

  • Supports GET, POST, PUT, DELETE, OPTIONS, PATCH and HEAD request methods
  • Static Route Patterns
  • Dynamic Route Patterns
  • Easy-to-use patterns
  • Allowance of Class@Method calls
  • Before Route Middlewares
  • Namespaces Supports
  • Route Groups Supports
  • Subdomain Supports
  • Subfolder Supports
  • Custom 404 Handling

Installation

Installation is possible using Composer, (*2)

composer require tkaratug/titan-router

Usage

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

use Titan\Router\Router as Route;

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

Route::execute();

Shorthands for single request methods are provided:, (*3)

Route::get('pattern', function() { /* ... */ });
Route::post('pattern', function() { /* ... */ });
Route::put('pattern', function() { /* ... */ });
Route::delete('pattern', function() { /* ... */ });
Route::options('pattern', function() { /* ... */ });
Route::patch('pattern', function() { /* ... */ });

Note: Routes must be hooked before Route::execute() is being called., (*4)

Class@Method calls

We can route to the class action like so:, (*5)

Route::get('/profile', 'User@viewProfile'); // Without namespace
Route::get('/product/{num}', 'App\Controllers\Product@detail'); // With namespace

Before Route Middlewares

Route::middleware(['auth'])->group(function(){
    Route::get('/dashboard', function(){ /* ... */} );
});

Namespaces Supports

Route::namespace('backend')->group(function(){
    // Controllers Within The "Controllers\Backend" Namespace
});

Subfolder Supports

Route::prefix('admin')->group(function(){
    Route::get('users', function(){
        // Matches The "/admin/users" URL
    });
});

Subdomain Supports

Route::domain('api.example.com')->group(function(){
    Route::get('user/{num}', function($id){
        //
    });
});

Multiple Groups

Route::namespace('backend')->prefix('admin')->middleware(['auth'])->group(function(){
    Route::get('/', 'Dashboard@index');
    // Controller = Controllers\Backend\Dashboard
    // URL = /admin
    // Middleware = Auth
});

Custom 404

Override the default 404 handler using Route::set404(function);, (*6)

Route::set404(function() {
    header('HTTP/1.1 404 Not Found');
    // ... do something special here
});

The Versions

14/11 2017

dev-master

9999999-dev https://github.com/tkaratug/titan-router

A simple and lightweight PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

routing router

25/10 2017

v1.0.0

1.0.0.0 https://github.com/tkaratug/titan-router

A simple and lightweight PHP router

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

routing router