Example #1
0
 /**
  * calls a command from a url
  * allows a command to be call with complete rules in tact
  *
  * @param string|boolean $uri -- the url to be used for the request. Defaults to false
  * @param array $data -- the data to be passed with the request. This mimics a GET or POST
  * @param boolean $log -- flag to log the current requested url in user's session. Defaults to false
  * @access public
  * @static
  * @return mixed
  */
 public static function url($uri = false, $data = array(), $log = false)
 {
     if ($uri) {
         $url_obj = System_Request_Url::getInstance()->setRequestUri($uri);
     }
     $objects = System_Request_Router::getInstance()->matchUrl();
     $request = new System_Request_Controller($objects);
     if (count($data)) {
         $request->setCommandData($data);
     }
     /**
      * log the request in the user's session
      */
     if ($log) {
         $uri = implode('/', System_Request_Url::getRequestVars());
         if (!in_array($uri, System_Request_Router::getIgnoredRoutes())) {
             $_SESSION['requested_uri'] = '/' . $uri;
         }
     }
     return $request->setUp()->process();
 }
Example #2
0
 /**
  * Rewrites the numeric index keys for the request_vars array
  *
  * @param array $new_keys -- an array holding the keys to be rewritten in the order in which they should be rewritten
  * @param array $new_values -- an array holding the values associated with the keys to be written. 
  * @access public
  * @return System_Request_Url
  */
 public function rewriteKeys(array $new_keys = array(), array $new_vals = array())
 {
     if (count($new_keys) > 0) {
         $new = array();
         $old = self::$_request_vars;
         foreach ($new_keys as $it_key => $key) {
             $new[$key] = isset($old[$it_key]) ? $old[$it_key] : $new_vals[$it_key];
         }
         self::$_request_vars = $new;
     }
     return $this;
 }
Example #3
0
 /**
  * the url vars for a request is passed and matched against the keys in the defined_routes property
  * if found, the array containing the command, view, and model objects is returned
  * 
  * @access public
  * @return array
  */
 public function matchUrl()
 {
     $return = array();
     $url_obj = System_Request_Url::getInstance();
     $url_parts = $url_obj->getRequestVars();
     $request_string = implode('/', $url_parts);
     $request_string = trim($request_string) == '' ? self::DEFAULT_COMMAND_OBJECT : $request_string;
     $rules = array();
     /**
      * Hack used to reorder the keys by length
      * This should be moved to an array lib for reuse
      * TODO: find another way to match a url against the a defined route
      */
     uksort($this->_routes, array('System_Request_Router', 'keyLengthSort'));
     foreach ($this->_routes as $url => $route_rules) {
         if (preg_match_all('/^' . preg_quote($url, '/') . '/i', $request_string, $matches)) {
             $return = self::getDefaultSetup();
             foreach ($route_rules as $key => $val) {
                 $return[$key] = $val;
             }
             $rules = $route_rules;
             if ($url === $request_string) {
                 break;
             }
         }
     }
     if (isset($rules['rewrites']) && count($rules['rewrites'])) {
         $url_obj->rewriteKeys($rules['rewrites'], $rules['defaults']);
     }
     return $return;
 }