From 90969f42c40378b75edab18aab0ccbb40af01d6c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 15 Mar 2007 03:11:21 +0000 Subject: [PATCH] Removing the Router and RouterController system because it's not very cross-platform and cross-server friendly --- PrinterRootElementForm.php | 17 +- PrinterRootElementPage.php | 2 +- Router.php | 333 ------------------------------------- RouterController.php | 83 --------- 4 files changed, 4 insertions(+), 431 deletions(-) delete mode 100644 Router.php delete mode 100644 RouterController.php diff --git a/PrinterRootElementForm.php b/PrinterRootElementForm.php index 6ffd910..69861ca 100644 --- a/PrinterRootElementForm.php +++ b/PrinterRootElementForm.php @@ -124,20 +124,9 @@ class BSPrinterRootElementForm extends BSPrinterRootElement */ public function paint() { - if (BSRegister::GetType('Router') AND (!defined('ISSO_ROUTER_NO_REWRITE') OR !constant('ISSO_ROUTER_NO_REWRITE'))) - { - $action = $this->controller . "." . $this->action; - } - else if (BSRegister::GetType('Router')) - { - $action = 'index.php?controller=' . $this->controller . '&action=' . $this->action; - } - else - { - $action = $this->controller; - array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action)); - } - return "\n
name . "\" action=\"$action\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n
"; + array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action)); + + return "\n
name . "\" action=\"" . $this->controller . "\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n
"; } } diff --git a/PrinterRootElementPage.php b/PrinterRootElementPage.php index 7db6f67..bd9e107 100644 --- a/PrinterRootElementPage.php +++ b/PrinterRootElementPage.php @@ -93,7 +93,7 @@ class BSPrinterRootElementPage extends BSPrinterRootElement function redirect() { - ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . (BSRegister::GetType('Router') ? (defined('ISSO_ROUTER_NO_REWRITE') ? "index.php?controller=$controller&action=$action" : "$controller.$action") : "$controller.php?action=$action") . '";') . ' + ' . ($postvars ? 'document.forms.postvars.submit();' : 'window.location = "' . "$controller.php?action=$action" . '";') . ' } //--> diff --git a/Router.php b/Router.php deleted file mode 100644 index 62f2d6c..0000000 --- a/Router.php +++ /dev/null @@ -1,333 +0,0 @@ -basePath = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['SCRIPT_NAME']); - } - - // ################################################################### - /** - * Listens for routing requests and handles them appropriately - */ - public function dispatch() - { - if ((defined('ISSO_ROUTER_NO_REWRITE') AND constant('ISSO_ROUTER_NO_REWRITE')) OR isset($_REQUEST['controller'])) - { - $this->request = (isset($_REQUEST['controller']) ? $_REQUEST['controller'] : ''); - $this->action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : ''); - $this->params = $_GET; - } - else - { - $request = str_replace($this->basePath, '', $_SERVER['REQUEST_URI']); - - $params = explode('/', $request); - $request = explode('.', $params[0]); - $this->request = $request[0]; - $this->action = (isset($request[1]) ? $request[1] : ''); - unset($params[0]); - - if (sizeof($params) == 0) - { - // do nothing - } - else if (sizeof($params) == 1) - { - $this->params[':id'] = $params[1]; - } - else - { - $key = ''; - for ($i = 1; $i <= sizeof($params); $i++) - { - if ($i == 1 AND $params["$i"][0] != '+') - { - $this->params[':id'] = $params["$i"]; - continue; - } - - if ($params["$i"] == '') - { - continue; - } - - if ($params["$i"][0] == '+') - { - if (!empty($key)) - { - $this->_error(sprintf(_('The paramter "%1$s" does not have a value'), $key)); - } - $key = substr($params["$i"], 1); - } - else - { - if (empty($key)) - { - $this->_error(sprintf(_('The value "%1$s" does not have a paramatized key'), $params["$i"])); - } - $this->params["$key"] = $params["$i"]; - $key = ''; - } - } - } - } - - $this->request = (empty($this->request) ? 'Index' : $this->request); - $this->action = (empty($this->action) ? 'Index' : $this->action); - - if (isset($this->map[ $this->request ])) - { - call_user_func_array(array($this, $this->map[ $this->request ][self::MAP_LOADER]), $this->map[ $this->request ][self::MAP_PARAMS]); - } - else - { - $this->_error(sprintf(_('Routing request "%1$s" not found in map'), $this->request)); - } - } - - // ################################################################### - /** - * Sets the error handler of the router; when an error occurs while - * routing, this method is called - * - * @param string Error handler name - */ - public function setErrorAction($name) - { - $this->errorAction = $name; - } - - // ################################################################### - /** - * Adds a directory of files to the maps, with the file names (without .php) - * as the map request name - * - * @param string Directory path - */ - public function addFileDirectory($path) - { - $path = BSFunctions::FetchSourcePath($path); - $controllers = BSFunctions::ScanDirectory($path); - - foreach ($controllers AS $file) - { - $controller = str_replace('.php', '', $file); - $this->addFileRequest($controller, $path . $file); - } - } - - // ################################################################### - /** - * Routes a request to the loading of a file; this is the most common - * routing request and it performs no extra functions - * - * @param string Request name - * @param string File name - */ - public function addFileRequest($request, $file) - { - $this->map["$request"] = array(self::MAP_LOADER => '_loadFile', self::MAP_PARAMS => array($file)); - } - - // ################################################################### - /** - * Adds a list of files to the mapping; the controller will become - * the file name without the .php extension - * - * @param string Search path - * @param string Prefix for the requests - */ - public function addControllerDirectory($path, $prefix = '') - { - $path = BSFunctions::FetchSourcePath($path); - $controllers = BSFunctions::ScanDirectory($path); - - foreach ($controllers AS $file) - { - $this->addController($prefix . str_replace('.php', '', $file), $path . $file); - } - } - - // ################################################################### - /** - * Routes a request to the controller system - * - * @param string Request name - * @param string Controller name; the file must be named .php and define a class Controller.php - */ - public function addController($request, $file) - { - $this->map["$request"] = array(self::MAP_LOADER => '_invokeController', self::MAP_PARAMS => array($file)); - } - - // ################################################################### - /** - * Includes a given file name - * - * @param string File name - */ - private function _loadFile($filename) - { - if (!file_exists($filename)) - { - $this->_error(sprintf(_('Cannot find the file "%1$s"'), $filename)); - } - include($filename); - } - - // ################################################################### - /** - * Loads and then invokes a controller - * - * @param string File name of the controller - */ - private function _invokeController($controller) - { - $this->_loadFile($controller); - - $controllerName = basename($controller, '.php'); - $className = "{$controllerName}Controller"; - - if (!class_exists($className)) - { - trigger_error('The controller "' . $className . '" does not exist and therfore cannot have actions forwarded to it'); - } - - if (!is_subclass_of($className, 'BSRouterController')) - { - trigger_error('Cannot invoke controller-style actions on a non-controller: requested controller is not of the type BSRouterController'); - } - - // these go out the door so BSInput will process them and merge them into BSInput->in[] - $_GET = $this->params; - $request = new $className(BSRegister::LoadModule('Input')); - - if (!method_exists($className, $this->action)) - { - trigger_error('Invalid action called on controller: ' . $className . ' does not respond to ' . $this->action . '()'); - } - - $request->{$this->action}(); - } - - // ################################################################### - /** - * Sends an error to the error action handler - * - * @param string Error message - */ - private function _error($errMsg) - { - if (function_exists($this->errorAction) OR (is_array($this->errorAction) AND method_exists($this->errorAction[0], $this->errorAction[1]))) - { - call_user_func($this->errorAction, $errMsg); - } - else - { - trigger_error($errMsg); - } - exit; - } -} - -/*=====================================================================* -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file diff --git a/RouterController.php b/RouterController.php deleted file mode 100644 index c3feeac..0000000 --- a/RouterController.php +++ /dev/null @@ -1,83 +0,0 @@ -params = $params; - } - - // ################################################################### - /** - * Does nothing if the request was sent via POST, and triggers an - * error if it was not - */ - protected function _verifyPostRequest() - { - if ($this->params->getHttpMethod() != 'post') - { - trigger_error('Action is intended to be executed from a POST request'); - } - } - - /** - * The default action (index) - */ - public abstract function Index(); -} - -/*=====================================================================* -|| ################################################################### -|| # $HeadURL$ -|| # $Id$ -|| ################################################################### -\*=====================================================================*/ -?> \ No newline at end of file -- 2.22.5