regexp-routing-table
By: fruffl | Date: Jan 10 2010 00:14 | Format: PHP | Expires: never | Size: 7.33 KB | Hits: 1151
- [ILLI_ROUTING_TABLE]
- => array (0015)
- [/]
- => array (0002)
- [controller]
- => string (9) Frontpage
- [regexp]
- => string (1) /
- [site/]
- => array (0003)
- [controller]
- => string (7) default
- [module]
- => string (4) site
- [regexp]
- => string (5) site/
- [site/blog(/d{1,})?]
- => array (0004)
- [controller]
- => string (4) blog
- [module]
- => string (4) site
- [params]
- => string (8) int∴page
- [regexp]
- => string (19) site/blog(/d{1,})?
- [site/blog/add-entry/]
- => array (0004)
- [action]
- => string (9) add_entry
- [controller]
- => string (4) blog
- [module]
- => string (4) site
- [regexp]
- => string (20) site/blog/add-entry/
- [site/blog/by-day(/d{4}/d{2}/d{2}(/d{1,})?)?]
- => array (0005)
- [action]
- => string (14) article_by_day
- [controller]
- => string (4) blog
- [module]
- => string (4) site
- [params]
- => string (38) int∴year,∴int∴month,∴int∴day,∴int∴page
- [regexp]
- => string (47) site/blog/by-day(/d{4}/d{2}/d{2}(/d{1,})?)?
- <?php
- FINAL CLASS FRUFFI_Dispatcher extends FRUFFI_InstancieOpziener
- {
- private static $valid_routing_args = array('controller', 'module', 'regexp', 'action', 'view', 'params');
- public static function init()
- {
- return self::instance(__CLASS__);
- }
- public function run()
- {
- $this->activate(__CLASS__);
- $this->execute();
- return $this;
- }
- protected function execute()
- {
- FRUFFI::registryAdd
- (
- 'FRUFFI_ENVIRONMENT_REMOTE_IP',
- $_SERVER['REMOTE_ADDR']
- );
- FRUFFI::registryAdd
- (
- 'FRUFFI_ENVIRONMENT',
- (
- FRUFFI::registryGet('FRUFFI_ENVIRONMENT_DEVELOPMENT_IP') == $_SERVER['REMOTE_ADDR']
- ? 'DEVELOPMENT'
- : 'PRODUCTION'
- )
- );
- FRUFFI::registryAdd
- (
- 'FRUFFI_ROUTING_TABLE',
- self::$routing
- );
- /*
- FRUFFI::registryAdd
- (
- 'FRUFFI_APPLICATION_ROUTING_INI',
- parse_ini_file(FRUFFI::registryGet('FRUFFI_FILE_SYSTEM_APP_ROUTING'), TRUE)
- );
- */
- require_once FRUFFI::registryGet('FRUFFI_FILE_SYSTEM_APP_ROUTING');
- FRUFFI::registryAdd
- (
- 'FRUFFI_ENVIRONMENT_URI',
- $this->getUri()
- );
- FRUFFI::registryAdd
- (
- 'FRUFFI_ENVIRONMENT_URIBASE',
- $this->getBase
- (
- FRUFFI::registryGet('FRUFFI_ENVIRONMENT_URI'),
- FRUFFI::registryGet('FRUFFI_ENVIRONMENT_REWRITE_BASE_'.FRUFFI::registryGet('FRUFFI_ENVIRONMENT'))
- )
- );
- FRUFFI::registryAdd
- (
- 'FRUFFI_ENVIRONMENT_URIPATH',
- $this->getPath
- (
- FRUFFI::registryGet('FRUFFI_ENVIRONMENT_URI'),
- FRUFFI::registryGet('FRUFFI_ENVIRONMENT_URIBASE')
- )
- );
- $this->dispatch(FRUFFI::registryGet('FRUFFI_ENVIRONMENT_URIPATH'));
- }
- {
- try
- {
- throw new FRUFFI_ExceptionDispatcher
- ('No Expression for Routing-Argument found.');
- throw new FRUFFI_ExceptionDispatcher
- ('Route '.$parsed['regexp'].' already defined.');
- foreach($route as $arg => $value)
- {
- throw new FRUFFI_ExceptionDispatcher
- ('Unknown classification for Routing-Argument: '.$arg);
- throw new FRUFFI_ExceptionDispatcher
- ('Value for argument '.$arg.' is not a string');
- if($arg != 'params')
- if($arg == 'params')
- {
- foreach($value as $index => $var)
- }
- $parsed[$arg] = $value;
- }
- self::$routing[$parsed['regexp']] = $route;
- FRUFFI::registryUpdate('FRUFFI_ROUTING_TABLE', self::$routing);
- }
- catch(FRUFFI_Exception $e){FRUFFI_Exception::w($e);}
- return $this;
- }
- private function dispatch($path)
- {
- {
- $this->invoke('/', FRUFFI::registryGet('FRUFFI_ROUTING_TABLE', '/'));
- return;
- }
- foreach(FRUFFI::registryGet('FRUFFI_ROUTING_TABLE') as $application => $config)
- {
- $path = '/'.$path;
- $application = '/'.$application;
- if($path == $application)
- {
- $this->invoke($application, $config);
- return;
- }
- {
- $this->invoke($application, $config);
- return;
- }
- }
- $this->routingNotFound();
- }
- private function routingNotFound()
- {
- FRUFFI::registryUpdate('FRUFFI_PUBLIC_ERROR_ROUTING', TRUE);
- }
- private function invoke($application, $config)
- {
- $config['module'] = 'default';
- $config['controller'] = 'default';
- $config['action'] = 'default';
- v($application, $config);
- }
- }
- /*================
- config-file
- */
- $this
- ->addRouting
- (
- (
- 'regexp' => '/',
- 'controller' => 'Frontpage'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/',
- 'controller' => 'default',
- 'module' => 'site'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog(/d{1,})?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'params' => 'int page'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog/by-year(/d{4}(/d{1,})?)?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'action' => 'article_by_year',
- 'params' => 'int year, int page'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog/list-by-year(/d{4}(/d{1,})?)?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'action' => 'articlelist_by_year',
- 'params' => 'int year, int page'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog/by-month(/d{4}/d{2}(/d{1,})?)?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'action' => 'article_by_month',
- 'params' => 'int year, int month, int page'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog/list-by-month(/d{4}/d{2}(/d{1,})?)?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'action' => 'articlelist_by_month',
- 'params' => 'int year, int month, int page'
- )
- )
- ->addRouting
- (
- (
- 'regexp' => 'site/blog/by-day(/d{4}/d{2}/d{2}(/d{1,})?)?',
- 'controller' => 'blog',
- 'module' => 'site',
- 'action' => 'article_by_day',
- 'params' => 'int year, int month, int day, int page'
- )
- );
Latest pastes
1 days ago
1 days ago
2 days ago
4 days ago
5 days ago