Skip to content

Commit

Permalink
Merge pull request #18 from nilopc/master
Browse files Browse the repository at this point in the history
Extended the Router class
  • Loading branch information
alombarte committed Apr 19, 2013
2 parents 1443824 + 13bd4b5 commit 1caa6e5
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 173 deletions.
21 changes: 13 additions & 8 deletions instances/Bootstrap.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ public static function autoload()
*/
public static function invokeController( $controller )
{
$controller_path = explode( '/', $controller );
$c = explode('::',$controller);
$controller_path = explode('/',$c[0]);

$class = '';
foreach ( $controller_path as $part )
{
$class .= ucfirst( $part );
}
do{
$class .= ucfirst( array_shift($controller_path) );
}while(!empty($controller_path));

$class .= 'Controller';

Expand Down Expand Up @@ -261,13 +261,18 @@ public static function dispatch( $controller = null )
$controller = $router->getController();
}
}

$c = explode('::',$controller);
if(!isset($c[1]))
{
$c[1] = 'build';
}
// This is the controller to use:
$ctrl = self::invokeController( $controller );
$ctrl = self::invokeController( implode('::',$c) );

// Save in params for future references:
$ctrl->addParams( array(
'controller_route' => $controller,
'controller_route' => $c[0],
'controller_method'=> $c[1],
) );

// Active/deactive auto-rebuild option:
Expand Down
8 changes: 7 additions & 1 deletion instances/CLBootstrap.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ public static function dispatch( $controller )
self::$language = 'en_US';

// This is the controller to use:
$ctrl = self::invokeController( $controller );
$c = explode('::',$controller);
if(!isset($c[1]))
{
$c[1] = 'build';
}
// This is the controller to use:
$ctrl = self::invokeController( implode('::',$c) );
$ctrl->build();

// Debug:
Expand Down
22 changes: 22 additions & 0 deletions instances/common/config/router_regex.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* This config file allows you to define Regex to be used in the router.config.php patterns field.
* The default values provided are:
$config['isInteger'] = '([1-9]([0-9]+)?\b)';
$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['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
Loading

0 comments on commit 1caa6e5

Please sign in to comment.