alombarte/SIFO — pull request #18 by nilopc (2013-04-18 17:48:55+00:00)
Title: Extended the Router class

Explanation
-------------------------
Extended the Router class adds new functionalities while keeping the global performance impact (very) low. Modified files to allow this new feature: Router.php, Controller.php Bootstrap.php and CLBootstrap.php.

This new method uses half compiled URLs. Replacement of the regex is done wisely using str_replace avoiding innecessary loops that would add up time.

For all loops, do_while is being used to shave off some time. (Note: I offer myself to rewrite most loops to do whiles to gain performance.)

It keeps 100% compatibility with the current URL set up, translating URLs and using controllers as domains and even using translations in domain set up. Putting it simple, it is backwards compatible.

Example
-------------------------
Usage of the new routing system in router.config.php
```php
//...
$config['__NO_ROUTE_FOUND__'] = 'static/index';
$config['__HOME__'] = 'home/index';

$config['admin']=array
(
'controller' => 'admin/index', //default Controller for /admin
'pattern' => array
(
//New controllers under the admin route
// :: => 'url pattern'
//If no is supplied, build is used
'admin/blog/index' => 'blog',
'admin/blog/post::create' => 'blog/post/create',
'admin/blog/post::update' => 'blog/post/{id}/update',
'admin/blog/post::delete' => 'blog/post/{id}/delete',

//USER ROUTING
'admin/users/index' => 'users',
'admin/users/index::create' => 'users/create',
'admin/users/index::update' => 'users/{uid}/update',
'admin/users/index::delete' => 'users/{uid}/delete',

//As many more as you like
),
//Placeholder array keys are defined in router_regex.config.php
'placeholders' => array
(
'isInteger' => array('{uid}','{id}')
)
);
```

Required new config file: router_regex.config.php allowing different regex. Here's the default set I've come up with.
```php

$config['isInteger'] = '(([1-9]\d?))';
$config['isHex'] = '(0[xX][0-9a-fA-F])';
$config['isFloat'] = '([-+]?\b[0-9]+(\.[0-9]+)?\b)';
$config['isBoolean'] = '^([0|1|true|false])';
$config['isAlphaNumeric'] = '([a-zA-z0-9_\-])';
$config['isString'] = '([\s\S])';
$config['isLocale'] = '([a-zA-Z][a-zA-Z])'; // eg: en
$config['isLongLocale'] = '([a-z][a-z]_[A-Z][A-Z])'; // eg: en_US
```