コード例 #1
0
ファイル: RouterBaseRule.php プロジェクト: justthefish/hesper
 /**
  * @return HttpUrl
  **/
 protected function getPath(HttpUrl $url)
 {
     $reducedUrl = clone $url;
     $base = RouterRewrite::me()->getBaseUrl();
     if (!$base instanceof HttpUrl) {
         throw new RouterException('Setup base url');
     }
     if (!$base->getScheme()) {
         $reducedUrl->setScheme(null)->setAuthority(null);
     }
     $reducedUrl->setQuery(null);
     if ($reducedUrl->getScheme() && $base->getScheme() != $reducedUrl->getScheme() || $reducedUrl->getAuthority() && $base->getAuthority() != $reducedUrl->getAuthority()) {
         return $reducedUrl;
     }
     $result = HttpUrl::create();
     $baseSegments = explode('/', $base->getPath());
     $segments = explode('/', $reducedUrl->getPath());
     $originalSegments = $segments;
     array_pop($baseSegments);
     while ($baseSegments && $segments && $baseSegments[0] == $segments[0]) {
         array_shift($baseSegments);
         array_shift($segments);
     }
     if ($baseSegments && $baseSegments[0]) {
         $segments = $originalSegments;
     }
     $result->setPath(implode('/', $segments));
     return $result;
 }
コード例 #2
0
 protected function resolvePath()
 {
     if (($base = RouterRewrite::me()->getBaseUrl()) && $this->scheme == $base->getScheme()) {
         return rtrim($base->getPath(), '/');
     } else {
         return '';
     }
 }
コード例 #3
0
 /**
  * @return string
  **/
 public static function url(array $urlOptions = [], $name, $reset = false, $encode = true)
 {
     return RouterRewrite::me()->assembly($urlOptions, $name, $reset, $encode);
 }
コード例 #4
0
 /**
  * @return Router
  */
 protected function getRouter()
 {
     return RouterRewrite::me()->addRoute(self::DEFAULT_ROUTE_NAME, RouterRegexpRule::create(self::ROUTE_REGEXP)->setMap([1 => 'area', 4 => 'id', 6 => 'action', 8 => 'format'])->setDefaults(['area' => self::DEFAULT_CONTROLLER, 'action' => self::DEFAULT_ACTION, 'id' => 0, 'format' => self::DEFAULT_FORMAT]));
 }