Created: 2014-05-18 16:36
Updated: 2014-06-12 14:13
License: mit


A route module for express-php


use express\express as express;

//Create the application called app and load core and route dependency
$app = express::module('app', ['core', 'route']);

//This function is a callback handler for a specific route (see below)
function handleRequest($response, $request, $routeParams, $testor)
  //Test and get value of $routeParams->id in one line
  $id = $testor($routeParams->id)->isNumeric()->isNotEmpty()->getValue();

  //Send a json answer
  $response->sendJson(array('user' => array('id' => $id)));

//This function is a callback that will be called on unknow route
function notFound($response)
  //Set HTTP status code

  //Send a response
  $response->send("NOT FOUD");

//All the function registred with config will be called automaticly with injected dependency
$app->config(function ($testor, $routeProvider) {

    //Register a route for /user/:id that will be handled by handleRequest callback. the id path parameter will be accecible in the $routeParams injectable
    $routeProvider->get('/user/:id', 'handleRequest');

    //Set a fallback handler


//This line is the execution entry point it MUST be called after everything else is set.
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more