示例#1
0
文件: app.php 项目: briancline/spire
 /**
  * We're trying to clean the REQUEST_URI in order to deduce the
  * controller to load, method of the controller to call, and what
  * arguments to send that method.
  *
  * For example:
  *  http://www.example.com/users/modify/83?profile=2
  * 
  * Where:
  *  http://www.example.com/		-- root url as specified in $global['url']
  *  users						-- is the controller we should instantiate and load
  *  modify						-- method of the controller we should call
  *  83							-- single argument to send to the modify method, but
  *								   there could easily be more than one argument
  *								   separated by additional /'s
  *  ?							-- indicating the beginning of the query string
  *								   and also the start of things we don't care about
  *								   here
  *
  * Effectively:
  *  $obj = new Users();
  *  $obj->modify(83);
  *
  * Defaults:
  *  If no controller is provided, we default to $global['default_controller'] and
  *  if no method is provided, we default to $global['default_method']
  */
 function prepareRequest()
 {
     if (isset($_SERVER['PATH_INFO'])) {
         $this->request = $_SERVER['PATH_INFO'];
     } else {
         $this->request = $_SERVER['REQUEST_URI'];
     }
     if ($this->request && !preg_match(Config::get('url_chars'), $this->request)) {
         return false;
     }
     // Remove the length of the query string off the end of the
     // request. +1 to the query string length to also remove the ?
     $this->queryString = $_SERVER['QUERY_STRING'];
     if (!empty($this->queryString) && false !== strpos($this->request, '?')) {
         $this->request = substr($this->request, 0, (strlen($this->queryString) + 1) * -1);
     }
     // Trash any leading slashes
     if ($this->request[0] == '/') {
         $this->request = substr($this->request, 1);
     }
     // Reroute this URI if necessary
     $this->request = Routing::determineFinalRoute($this->request);
     $this->request = explode('/', $this->request);
     $this->requestLength = count($this->request);
     // Trash the index.php match
     if ($this->request[0] == 'index.php') {
         array_shift($this->request);
     }
     // Grab the controller, method and arguments
     $this->requestController = array_shift($this->request);
     $this->requestMethod = array_shift($this->request);
     $this->requestArguments = $this->request;
     if (!$this->requestController) {
         $this->requestController = Config::get('default_controller');
     }
     if (!$this->requestMethod) {
         $this->requestMethod = Config::get('default_method');
     }
     return true;
 }