PHP Classes

Kompat PHP Router Library: Route HTTP requests to classes or functions

Recommend this page to a friend!
     
  Info   Example   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: 107 All time: 9,683 This week: 39Up
Version License PHP version Categories
kompat 1GNU General Publi...5HTTP, PHP 5, Web services
Description 

Author

This package can route HTTP requests to classes or functions.

It can add patterns of the HTTP request URI path that it will handle and associate them with functions.

The package can also handle groups of routes and split them in sub-routes to be handled by separate classes or functions, with optional support to require that the request passes a token via an special HTTP header.

Picture of Luis Toscano
  Performance   Level  
Name: Luis Toscano <contact>
Classes: 8 packages by
Country: Colombia Colombia
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Example

<?php

ini_set
('display_errors',1);

include
'core/model.class.php';
include
'router.php';

$r = new Router();

$r->add('/articulos/?', function($id){
    echo
'articulo #'.$id;
});

$r->add('/carro/?', '@models/carros/get');


echo
'<pre>';
$r->group('/api', function($rr){
    GLOBAL
$r;

   
$r->add('/usuario/?', function($id){
        echo
$id;
    });

   
$r->add('/carros', '@models/carros');

},[
'needToken' => true]);
echo
'</pre>';


Details

Kompat

Micro Route Controller in PHP.

Esta clase busca simplificar la utilizacion de un sistema de ruteo en aplicaciones sencillas para aquellos que no les gusta utilizar frameworks o que les parece que estos tienen demasiadas cosas que no se utilizan todas.

actualmente puede recibir y procesar la ruta de dos formas, la primera es una forma sencilla y la segunda es agrupanto un grupo de rutas bajo un namespace determinado, y su procesamiento tambien tiene dos formas de utilizar, la primera mediante callback y la segunda procesando la peticion en una clase que actual como controllador.

en el ejemplo se muestran las diferentes formas.

El Siguiente es un ejemplo de como se utiliza.

<?php

ini_set('display_errors',1);

include 'core/model.class.php';
include 'router.php';

$r = new Router();

$r->add('/articulos/?', function($id){
	echo 'articulo #'.$id;
});

$r->add('/carro/?', '@models/carros/get');


echo '<pre>';
$r->group('/api', function($rr){
	GLOBAL $r;

	$r->add('/usuario/?', function($id){
		echo $id;
	});

	$r->add('/carros', '@models/carros');

},['needToken' => true]);
echo '</pre>';

  Files folder image Files (5)  
File Role Description
Files folder imagecore (1 file)
Files folder imagemodels (1 file)
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file README.md Doc. Read me
Plain text file router.php Class Class source

  Files folder image Files (5)  /  core  
File Role Description
  Plain text file model.class.php Class Class source

  Files folder image Files (5)  /  models  
File Role Description
  Plain text file carros.model.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:107
This week:0
All time:9,683
This week:39Up