getRoute() public static method

public static getRoute ( $url )
Exemplo n.º 1
0
 /**
  *  Faz a interpretação da URL, identificando as partes da URL.
  * 
  *  @param string $url URL a ser interpretada
  *  @return array URL interpretada
  */
 public function parseUrl($url = null)
 {
     $here = Mapper::normalize(is_null($url) ? Mapper::here() : $url);
     $url = Mapper::getRoute($here);
     $prefixes = join("|", Mapper::getPrefixes());
     $parts = array("here", "prefix", "controller", "action", "id", "extension", "params");
     preg_match("/^\\/(?:({$prefixes})(?:\\/|(?!\\w)))?(?:([a-z_-]*)\\/?)?(?:([a-z_-]*)\\/?)?(?:(\\d*))?(?:\\.([\\w]+))?(?:\\/?(.*))?/i", $url, $reg);
     foreach ($parts as $k => $key) {
         $this->path[$key] = $reg[$k];
     }
     $this->path["namedParams"] = $this->path["params"] = array();
     foreach (split("/", $reg[6]) as $param) {
         if (preg_match("/([^:]*):([^:]*)/", $param, $reg)) {
             $this->path["namedParams"][$reg[1]] = urldecode($reg[2]);
         } elseif ($param != "") {
             $this->path["params"][] = urldecode($param);
         }
     }
     $this->path["here"] = $here;
     if (empty($this->path["controller"])) {
         $this->path["controller"] = Mapper::getRoot();
     }
     if (empty($this->path["action"])) {
         $this->path["action"] = "index";
     }
     if (!empty($this->path["prefix"])) {
         $this->path["action"] = "{$this->path['prefix']}_{$this->path['action']}";
     }
     if (empty($this->path["id"])) {
         $this->path["id"] = null;
     }
     if (empty($this->path["extension"])) {
         $this->path["extension"] = Config::read("defaultExtension");
     }
     return $this->path;
 }