phpalchemy/routing

PHP Alchemy Routing Component

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

This package is not auto-updated.

Last update: 2024-04-22 13:43:22 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,
)