phpalchemy/routing

PHP Alchemy Routing Component

Installs: 1

Dependents: 0

Stars: 2

Watchers: 1

Language: PHP

v1.0 2013-09-03 20:59 UTC

README

Build Status

Faster & simple Http Routing

This is a Simple but faster URL Http routing library

Sample Use:

use Alchemy\Component\Routing\Mapper;
use Alchemy\Component\Routing\Route;

$mapper = new Mapper();

$mapper->connect(
    'home_route',
    new Route(
        '/',
        array(
            '_controller' => 'sample',
            '_action' => 'index'
        )
    )
);

$mapper->connect(
    'to_index_route',
    new Route(
        '/{_controller}',
        array('_action' => 'index')
    )
);

$mapper->connect(
    'complete_route',
    new Route(
        '/{_controller}/{_action}'
    )
);

$mapper->connect(
    'complete_route',
    new Route(
        '/leap_year/{year}',  // pattern
        array(  // defaults
            '_controller' => 'Validator',
            '_action' => 'leapYear'
        ),
        array( // requeriments
            'year' => '\d+',
            '_method' => array('GET', 'POST')
        )
    )
);

print_r($mapper->match('/home/sample'));
Array
(
    [_controller] => home,
    [_action] => sample
)

print_r($mapper->match('/leap_year/2012'));
Array
(
    [_controller] => Validator,
    [_action] => leapYear,
    [year] => 2012,
)