Ejemplo n.º 1
0
 /**
  * 获取route的host
  * @param RouteInterface $route
  * @param array $parameters
  * @return string
  */
 protected function getRouteHost(RouteInterface $route, $parameters)
 {
     // 如果route没有主机域名限制则直接使用环境中主机
     $requireHost = $route->getHost();
     if (empty($requireHost)) {
         return $this->context->getHost();
     }
     // 有限制则根据route的host限制生成域名
     return $this->formatRouteHostOrPath($requireHost, $parameters, $route->getRequirements());
 }
Ejemplo n.º 2
0
 /**
  * 匹配host
  * @param RouteInterface $route
  * @return boolean
  */
 protected function matchHost(RouteInterface $route)
 {
     if (empty($route->getHost())) {
         return true;
     }
     if (preg_match($route->compile()->getHostRegex(), $this->context->getHost(), $matches)) {
         $routeParameters = array_intersect_key($matches, array_flip($route->getVariables()));
         $route->setParameter('_hostMatches', $routeParameters);
         return true;
     }
     return false;
 }