示例#1
0
 /**
  * Matches a user submitted path. Assigns and returns an array of variables
  * on a successful match.
  *
  * If a request object is registered, it uses its setModuleName(),
  * setControllerName(), and setActionName() accessors to set those values.
  * Always returns the values as an array.
  *
  * @param string $path Path used to match against this routing map
  * @return array An array of assigned values or a false on a mismatch
  */
 public function match($path)
 {
     $this->_setRequestKeys();
     $values = array();
     $params = array();
     $path = trim($path, self::URI_DELIMITER);
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
             $values[$this->_moduleKey] = array_shift($path);
             $this->_moduleValid = true;
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_controllerKey] = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_actionKey] = array_shift($path);
         }
         if ($numSegs = count($path)) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
             }
         }
     }
     $this->_values = $values + $params;
     return $this->_values + $this->_defaults;
 }
示例#2
0
文件: Module.php 项目: Tony133/zf-web
 /**
  * Matches a user submitted path. Assigns and returns an array of variables
  * on a successful match.
  *
  * If a request object is registered, it uses its setModuleName(),
  * setControllerName(), and setActionName() accessors to set those values.
  * Always returns the values as an array.
  *
  * @param string $path Path used to match against this routing map
  * @return array An array of assigned values or a false on a mismatch
  */
 public function match($path)
 {
     $this->_setRequestKeys();
     $values = array();
     $params = array();
     $path = trim($path, self::URI_DELIMITER);
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
             $values[$this->_moduleKey] = array_shift($path);
             $this->_moduleValid = true;
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_controllerKey] = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_actionKey] = array_shift($path);
         }
         if ($numSegs = count($path)) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 /*
                  * check if key is meant as array as in index/index/key[]/one/key[]/two/key[]/three
                  */
                 if (substr($key, -2) === '[]') {
                     //key is an array index
                     $index = substr($key, 0, strlen($key) - 2);
                     if (array_key_exists($index, $params)) {
                         if (is_array($params[$index])) {
                             //is already an array, ad value
                             $params[$index][] = $val;
                         } else {
                             //the key is already registered, it will not be overwritten
                         }
                     } else {
                         //create array at $index and place first value
                         $params[$index] = array($val);
                     }
                 } else {
                     //regular key
                     $params[$key] = $val;
                 }
             }
         }
     }
     $this->_values = $values + $params;
     return $this->_values + $this->_defaults;
 }
示例#3
0
文件: Module.php 项目: Tony133/zf-web
 /**
  * Matches a user submitted path. Assigns and returns an array of variables
  * on a successful match.
  *
  * If a request object is registered, it uses its setModuleName(),
  * setControllerName(), and setActionName() accessors to set those values.
  * Always returns the values as an array.
  *
  * @param string $path Path used to match against this routing map
  * @return array An array of assigned values or a false on a mismatch
  */
 public function match($path)
 {
     $this->_setRequestKeys();
     $values = array();
     $params = array();
     $path = trim($path, self::URI_DELIMITER);
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
             $values[$this->_moduleKey] = array_shift($path);
             $this->_moduleValid = true;
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_controllerKey] = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_actionKey] = array_shift($path);
         }
         if ($numSegs = count($path)) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 /*
                  * check if key is meant as array as in index/index/var/one/var/two/var/three
                  * or even index/index/var[]/one/var[]/two
                  */
                 if (array_key_exists($key, $params)) {
                     if (is_array($params[$key])) {
                         //is already an array, ad value
                         $params[$key][] = $val;
                     } else {
                         //save first element
                         $first_element = $params[$key];
                         //replace key value with array with key value as first element
                         $params[$key] = array($first_element);
                         //value is next element
                         $params[$key][] = $val;
                     }
                 } else {
                     //regular key
                     $params[$key] = $val;
                 }
             }
         }
     }
     $this->_values = $values + $params;
     return $this->_values + $this->_defaults;
 }
示例#4
0
 /**
  * Matches a user submitted path. Assigns and returns an array of variables
  * on a successful match.
  *
  * If a request object is registered, it uses its setModuleName(),
  * setControllerName(), and setActionName() accessors to set those values.
  * Always returns the values as an array.
  *
  * @param string $path Path used to match against this routing map
  * @return array An array of assigned values or a false on a mismatch
  */
 public function match($path)
 {
     $this->_setRequestKeys();
     if ($this->hasTranslator()) {
         $translateMessages = $this->getTranslator()->getMessages();
     }
     $values = array();
     $params = array();
     if (!$this->isPartial()) {
         $path = trim($path, self::URI_DELIMITER);
     }
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if ($this->_dispatcher && ($this->_dispatcher->isValidModule($path[0]) || $this->hasTranslator() && !empty($translateMessages) && false !== ($moduleTranslated = array_search($path[0], $translateMessages)) && $this->_dispatcher->isValidModule($moduleTranslated))) {
             $module = array_shift($path);
             if ($this->hasTranslator() && !empty($translateMessages)) {
                 $moduleTranslated = array_search($module, $translateMessages);
                 if (!empty($moduleTranslated)) {
                     $module = $moduleTranslated;
                 }
             }
             $values[$this->_moduleKey] = $module;
             $this->_moduleValid = true;
         }
         if (count($path) && !empty($path[0])) {
             $controller = array_shift($path);
             if ($this->hasTranslator() && !empty($translateMessages)) {
                 $controllerTranslated = array_search($controller, $translateMessages);
                 if (!empty($controllerTranslated)) {
                     $controller = $controllerTranslated;
                 }
             }
             $values[$this->_controllerKey] = $controller;
         }
         if (count($path) && !empty($path[0])) {
             $action = array_shift($path);
             if ($this->hasTranslator() && !empty($translateMessages)) {
                 $actionTranslated = array_search($action, $translateMessages);
                 if (!empty($actionTranslated)) {
                     $action = $actionTranslated;
                 }
             }
             $values[$this->_actionKey] = $action;
         }
         if ($numSegs = count($path)) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
             }
         }
     }
     if ($this->isPartial()) {
         $this->setMatchedPath($path);
     }
     $this->_values = $values + $params;
     return $this->_values + $this->_defaults;
 }
示例#5
0
 /**
  * Matches a user submitted path. Assigns and returns an array of variables
  * on a successful match.
  *
  * If a request object is registered, it uses its setModuleName(),
  * setControllerName(), and setActionName() accessors to set those values.
  * Always returns the values as an array.
  *
  * @param string $path Path used to match against this routing map
  * @return array An array of assigned values or a false on a mismatch
  */
 public function match($path, $partial = false)
 {
     $numbers = new Ml_Model_Numbers();
     if (HOST_MODULE == "api") {
         return array("controller" => "notstatic", "action" => "error", "module" => "api");
     } else {
         if (HOST_MODULE == "default") {
             //@todo this is a workaround for another resource: the tag system
             //the Zend_Controller_Router_Route_Regex don't work with utf-8
             //despite trying the hack http://framework.zend.com/issues/browse/ZF-6661
             //it didn't work
             //clear this part of the code when everything is ok
             //and only let the static=>docs
             $path = explode("/", $path, 5);
             if (isset($path[2]) && $path[2] == "tags" && isset($path[3])) {
                 //could be using regex...
                 $username = $path[1];
                 if ($username) {
                     $tag = urldecode($path[3]);
                     if (!isset($path[4])) {
                         $page = "1";
                     } else {
                         if (mb_substr($path[4], 0, 4) == "page") {
                             $tryPage = mb_substr($path[4], 4);
                             if ($numbers->isNaturalDbId($tryPage)) {
                                 $page = $tryPage;
                             }
                         }
                     }
                     if (isset($page)) {
                         return array("username" => $username, "tag" => $tag, "page" => $page, "controller" => "tagspages", "action" => "tagpage", "module" => "default");
                     }
                 }
             }
             //end of workaround
             return array("controller" => "static", "action" => "docs", "module" => "default");
         }
     }
     $this->_setRequestKeys();
     $values = array();
     $params = array();
     if (!$partial) {
         $path = trim($path, self::URI_DELIMITER);
     } else {
         $matchedPath = $path;
     }
     if ($path != '') {
         $path = explode(self::URI_DELIMITER, $path);
         if ($this->_dispatcher && $this->_dispatcher->isValidModule($path[0])) {
             $values[$this->_moduleKey] = array_shift($path);
             $this->_moduleValid = true;
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_controllerKey] = array_shift($path);
         }
         if (count($path) && !empty($path[0])) {
             $values[$this->_actionKey] = array_shift($path);
         }
         if ($numSegs = count($path)) {
             for ($i = 0; $i < $numSegs; $i = $i + 2) {
                 $key = urldecode($path[$i]);
                 $val = isset($path[$i + 1]) ? urldecode($path[$i + 1]) : null;
                 $params[$key] = isset($params[$key]) ? array_merge((array) $params[$key], array($val)) : $val;
             }
         }
     }
     if ($partial) {
         $this->setMatchedPath($matchedPath);
     }
     $this->_values = $values + $params;
     return $this->_values + $this->_defaults;
 }