コード例 #1
0
ファイル: Dir.php プロジェクト: newairhost/HTRouter
 protected function _updateUrl($url, $path)
 {
     $utils = new \HTRouter\Utils();
     $url = parse_url($url);
     // Is it an absolute url?
     if ($path[0] == "/") {
         $url['path'] = $path;
         // Replace
     } else {
         $url['path'] .= $path;
         // Append
     }
     $url = $utils->unparse_url($url);
     return $url;
 }
コード例 #2
0
ファイル: Rule.php プロジェクト: newairhost/HTRouter
 /**
  * Either returns OK, DECLINED, or a HTTP status code
  *
  * @param \HTRouter\Request $request
  * @return \HTRouter\Module\Rewrite\Result
  * @throws \LogicException
  */
 function rewrite(\HTRouter\Request $request)
 {
     $this->_request = $request;
     // Create default return object
     $result = new Result();
     $result->vary = array();
     $result->rc = \HTRouter::STATUS_OK;
     $utils = new \HTRouter\Utils();
     $request->setUri($request->getFilename());
     // Strip per directory stuff... :|
     // Check if pattern matches
     $regex = "|" . $this->_pattern . "|";
     // Don't separate with / since it will be used a path delimiter
     if ($this->hasFlag(Flag::TYPE_NOCASE)) {
         $regex .= "i";
     }
     $match = preg_match($regex, $request->getUri(), $matches) >= 1;
     $this->_ruleMatches = $matches;
     if ($this->_patternNegate) {
         $match = !$match;
     }
     // We didn't match the pattern (or negative pattern). Return unmodified url_path
     if (!$match) {
         $result->rc = \HTRouter::STATUS_OK;
         return $result;
     }
     // @TODO; Skip the conditions for now...
     //        $ret = $this->matchConditions();
     //        if (! $ret) {
     //            $result->rc = \HTRouter::STATUS_OK;
     //            return $result;
     //        }
     if ($this->_substitutionType == self::TYPE_SUB_NONE) {
         // This is a dash, so no need to rewrite
         $result->rc = \HTRouter::STATUS_OK;
         return $result;
     }
     if ($this->_substitutionType == self::TYPE_SUB) {
         $uri = $this->expandSubstitutions($this->_substitution, $this->getRequest(), $this->_ruleMatches, $this->_condMatches);
         $src_url = parse_url($request->getUri());
         $dst_url = parse_url($uri);
         if (!isset($src_url['host'])) {
             $src_url['host'] = "";
         }
         if (!isset($dst_url['host'])) {
             $dst_url['host'] = "";
         }
         // If it's the same host or redirect flag is on, we do a redirect
         if ($dst_url['host'] != $src_url['host'] || $this->hasFlag(Flag::TYPE_REDIRECT)) {
             $url = $utils->unparse_url($dst_url);
             $request->appendOutHeaders("Location", $url);
             $result->rc = \HTRouter::STATUS_HTTP_MOVED_PERMANENTLY;
             return $result;
         }
         // Change url_path
         $request->setFilename("/" . $dst_url['path']);
         // Check if we need to append our original arguments
         if (isset($dst_url['query'])) {
             parse_str($dst_url['query'], $newArgs);
         } else {
             $newArgs = array();
         }
         if ($this->hasFlag(Flag::TYPE_QSA)) {
             // We need to set new flags
             $request->setArgs(array_merge($request->getArgs(), $newArgs));
         } else {
             $request->setArgs($newArgs);
         }
         $result->rc = \HTRouter::STATUS_OK;
         return $result;
     }
     // @TODO: It should be a sub_none or sub type. Must be changed later
     // @codeCoverageIgnoreStart
     throw new \LogicException("We should not be here!");
     // @codeCoverageIgnoreEnd
 }