Symfony路由无法匹配自己生成的uri


symfony route fails to match its own generated uri

我使用Symfony Routing Component定义了一个路由

使用这个路由生成一个uri。'https://domain.tl/login'

当导航到那个uri时,UrlMatcher匹配失败并抛出

// $_SERVER['REQUEST_URI'] == 'https://domain.tl/login' 
// old situation
//$request_context = new RequestContext($_SERVER['REQUEST_URI']);
// problem solved:
$protocol = $_SERVER['SERVER_PORT'] == 80 ? 'http':'https';
$request_context = new RequestContext($_SERVER['REQUEST_URI']);
$request_context->setScheme($protocol);

$routes = new RouteCollection;
// should match: https://domain.tl/login
$routes->add('login', new Route('login', array(), array(), array(), '', array('https')));
// reverse routing
$base_uri = new RequestContext;
$base_uri->setHost($_SERVER['HTTP_HOST']);
$generator = new UrlGenerator($routes, $base_uri);
var_dump($generator->generate('login')); // gives: https://domain.tl/login
try
{
    $matcher = new UrlMatcher($routes, $request_context);
    $matcher->match($_SERVER['REQUEST_URI']); // throws
    die('match');
}
catch('Symfony'Component'Routing'Exception'ResourceNotFoundException $ex)
{
    die('no match');
}

我真的很难弄清楚如何在不深入路由组件代码的情况下调试它。希望我错过了一些明显的东西:)

edit:该路由不受https的限制。这个限制是必需的。

edit2: it works!我在上面的代码

中实现了修复

是的,你说的问题只在https上,但是如果你检查HTTP_HOST的值,不要说它是http或https。我敢肯定,它会工作没有https限制