Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see \Slince\Router\Validator\ValidatorInterface::validate()
  */
 function validate(RouteInterface $route, RequestContext $context)
 {
     $matches = [];
     $result = !$route->getCompiledRoute()->getHostRegex() || preg_match($route->getCompiledRoute()->getHostRegex(), $context->getHost(), $matches);
     if ($result) {
         $route->setReport(self::$id, $matches);
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * (non-PHPdoc)
  * @see \Slince\Router\Validator\ValidatorInterface::validate()
  */
 function validate(RouteInterface $route, RequestContext $context)
 {
     $matches = [];
     $result = preg_match($route->getCompiledRoute()->getRegex(), rawurldecode($context->getParameter('path')), $matches);
     if ($result) {
         $route->setReport(self::$id, $matches);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * (non-PHPdoc)
  * @see \Slince\Router\GeneratorInterface::generate()
  */
 function generate(RouteInterface $route, $parameters = [], $absolute = true)
 {
     $compiledRoute = $route->getCompiledRoute();
     // 提供的初始化route parameter
     $this->_routeParameters = array_merge($this->_context->getParameters(), $parameters);
     $uri = '';
     // 生成绝对路径,需要构建scheme domain port
     if ($absolute) {
         list($scheme, $port) = $this->_getRouteSchemeAndPort($route);
         $domain = $this->_getRouteDomain($route);
         $uri .= "{$scheme}://{$domain}{$port}";
     }
     $uri .= $this->_getRoutePath($route);
     // 提供的多出的数据作为query string
     $extra = array_diff_key($parameters, $route->getRequirements());
     if ($extra && ($query = http_build_query($extra, '', '&'))) {
         $uri .= '?' . $query;
     }
     return $uri;
 }
Esempio n. 4
0
 /**
  * 处理路由参数
  * 
  * @param RouteInterface $route
  * @return void
  */
 protected function _handleRouteParameters(RouteInterface $route)
 {
     $catchedParameters = call_user_func_array('array_merge', $route->getReport());
     $variables = $route->getCompiledRoute()->getVariables();
     $routeParameters = array_intersect_key($catchedParameters, array_flip($variables));
     $route->setRouteParameters($routeParameters);
 }