/** * Initialize dispatch and detects if a custom dispatcher should be used within the current scope. * If no scope is defined, the default dispatcher will be instantiated. * * @access public * @return void * @static */ public static function initialize() { $params = Router::current(); $dispatch = null; if (!empty(self::$__mapping)) { // Specific controller and container if (isset(self::$__mapping[$params['container'] . '.' . $params['controller']])) { $dispatch = self::$__mapping[$params['container'] . '.' . $params['controller']]; // All controllers within a specific container } else { if (isset(self::$__mapping[$params['container'] . '.*'])) { $dispatch = self::$__mapping[$params['container'] . '.*']; // Specific controller within any container } else { if (isset(self::$__mapping['*.' . $params['controller']])) { $dispatch = self::$__mapping['*.' . $params['controller']]; // Apply to all controllers and containers } else { if (isset(self::$__mapping['*.*'])) { $dispatch = self::$__mapping['*.*']; } } } } } if ($dispatch) { $Dispatcher = $dispatch($params); } else { switch (Environment::detect()) { case 'development': $Dispatcher = new \titon\modules\dispatchers\front\FrontDev($params); break; default: $Dispatcher = new \titon\modules\dispatchers\front\Front($params); break; } } if ($Dispatcher instanceof \titon\modules\dispatchers\DispatcherInterface) { $Dispatcher->run(); exit; } throw new Exception(sprintf('%s Dispatcher must implement the \\titon\\modules\\dispatchers\\DispatcherInterface.', $dispatch)); }
<?php /** * Setup and initialize any core components or modules. * * @copyright Copyright 2009, Titon (A PHP Micro Framework) * @link http://titonphp.com * @license http://opensource.org/licenses/bsd-license.php (The BSD License) */ namespace app\config; use titon\core\Environment; use titon\system\Dispatch; use titon\system\Hook; /** * Overwrite the default dispatcher with a custom dispatcher. * Can also restrict the dispatcher to a specific scope. */ switch (Environment::detect()) { case 'production': Dispatch::setup(function ($params) { return new \titon\modules\dispatchers\front\Front($params); }); break; }