mikeismint/fruit

There is no license information available for the latest version (dev-master) of this package.

dev-master 2017-04-07 21:40 UTC

This package is not auto-updated.

Last update: 2024-04-13 15:33:57 UTC


README

My first attempt at a simple PHP router. Influenced by AltoRouter

Usage

$router = new Fruit();

// map single route
$router->addRoute('GET', '/', 'Controller#Method');

// map post details page
$router->addRoute('GET', '/^posts\/id\/(?P<id>\d+)$/', 'Controller#Method');

// map multiple routes
$router->addRoutes(array(
    array('GET', '/', 'Controller#Method'),
    array('GET', '/^posts\/id\/(?P<id>\d+)$/', 'Controller#Method'),
));

Other features

  • Accepts multiple HTTP methods separated by |
  • Uses regex to match URL pattern
  • Accepts optional fourth parameter to name routes