2017 © Pedro Peláez
 

library router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.

image

hybridlogic/router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.

  • Saturday, January 12, 2013
  • by Dachande663
  • Repository
  • 4 Watchers
  • 9 Stars
  • 51 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions., (*1)

Build Status, (*2)

0.0 Table of Contents

  • Introduction
  • Examples
  • Format
  • Running Tests
  • Troubleshooting
  • Changelog

1.0 Introduction

Router is a very simple URI request routing library, designed for providing a simple front controller for applications. A request is run against a dictionary of routes, and the first one to match is executed., (*3)

It supports expansions for common expressions (numeric, slugs etc), along with full regexes and optional parameter support., (*4)

Can be used in front of a full MVC stack, or with simple in-place closures., (*5)

2.0 Examples

$router = new \HybridLogic\Router;

$router->get('about', function(){
    echo 'About Us';
});

$router->run();

3.0 Format

Each route you wish to match should have a rule. The rule shouldn't include a beginning or ending slash, except for the homepage, which is just /., (*6)

When defining a route, you can specify which HTTP methods it should respond to (GET, POST etc). For example, to only allow GET requests, use ->get(...). A utility method for quickly adding GET and POST is provided via ->any(...)., (*7)

A route pattern matches a request exactly, that means sub- directories are not included, for example "about" would match /about, but not /about-us or /about/john-smith., (*8)

There are three default regex expressions provided:, (*9)

  • :num Matches any numeric value ([0-9]+)
  • :any Matches alphanumeric values, including - and ([a-z0-9-]+)
  • :all Matches anything, including slashes, will override anything after it

You can also provide your own regex, e.g., (*10)

/about/:[a-z][a-z0-9]+

To make a section optional, simply put a question mark (?) at the end, e.g., (*11)

/about/:any?

Example patterns:, (*12)

Pattern Matches Description
/ / Homepage
about /about Matches optional trailing slash
about/:any? /about/john Match optional directories
archive/:num/:num? /archive/2012/06 Match archive pattern
:all /matches/anything Catch-all handler (404s)

4.0 Running Tests

phpunit tests, (*13)

5.0 Troubleshooting

Nothing here yet., (*14)

6.0 Changelog

  • [2012-12-17] Initial Version
  • [2012-12-18] Removed 404 handler
  • [2012-12-19] Add any() and all() methods.

The Versions

12/01 2013

dev-master

9999999-dev https://github.com/Dachande663/PHP-Router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

request router uri

12/01 2013

v1.0.2

1.0.2.0 https://github.com/Dachande663/PHP-Router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

request router uri

12/01 2013

v1.0.1

1.0.1.0 https://github.com/Dachande663/PHP-Router

A drop dead simple URI routing library for PHP, with support for optional parameters and regular expressions.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

request router uri

02/01 2013

v1.0.0

1.0.0.0

A simple request routing library

  Sources   Download

The Requires

  • php >=5.3.0

 

request router uri