2017 © Pedro Peláez
 

library router

Lightweight standalone routing library for PHP

image

lemmon/router

Lightweight standalone routing library for PHP

  • Tuesday, April 26, 2016
  • by lemmon
  • Repository
  • 1 Watchers
  • 0 Stars
  • 34 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Lemmon Router

Lemmon Router is a lightweight standalone routing library for PHP 7., (*1)

  • Flexible regular expression routing
  • Simple and lightweight
  • RESTful routing
  • Fast (100k requests/second)
  • Mod_Rewrite is not required, although supported; extreme portability for rapid development

Getting started

  1. PHP 7.x is required
  2. Install Lemmon Router using Composer (recommended) or manually

Composer Installation

  1. Get Composer
  2. Require Lemmon Router with php composer.phar require lemmon/router
  3. Add the following to your application's main PHP file: require 'vendor/autoload.php';

Examples

<?php

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

$r = new Lemmon\Router\Router;
$r->match('hello-world', function() {
    echo 'Hello World!';
});
$r->dispatch();

Example 1 - Respond to all requests, (*2)

$r->match(function() {
    # matches everything
});

Example 2 - Match parameters, (*3)

$r->match('{controller}/{action}', function($r) {
    # $r->controller;
    # $r->action;
});

Example 3 - RESTful routing, (*4)

$r->match(['GET', 'PUT'], '{controller}(/(?<trail>{action:read|write}/{id:num:1,3=1})!)', ['controller' => '\w+'], function($r) {
    # matches only GET and PUT requests
    # matches either 'controller' or 'controller/action/id' when route conditions are met
    # controller can be any word
    # action is either read or write
    # id must be numeric of length 1 to 3, default is 1
});

The Versions

26/04 2016

dev-master

9999999-dev https://github.com/lemmon/router

Lightweight standalone routing library for PHP

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Jakub Pelak

boilerplate routing router sinatra